local U=game:GetService("\087\111\114\107\115\112\097\099\101")local c=game:GetService("\082\117\110\083\101\114\118\105\099\101")local I={}function I.reparentFromWorkspaceIfNeeded(I,G)assert(typeof(I)=="\073\110\115\116\097\110\099\101","\066\097\100 \112\097\114\101\110\116")assert(type(G)=="\115\116\114\105\110\103","\066\097\100 \110\097\109\101")local j=U:FindFirstChild(G)local Q=I:FindFirstChild(G)if j then if Q then error(("\068\117\112\108\105\099\097\116\101 \099\111\110\116\097\105\110\101\114 \105\110 \037\113 \097\110\100 \037\113"):format(j:GetFullName(),Q:GetFullName()))end if c:IsRunning()then j.Parent=I end return j end if not Q then error(("\078\111 \116\101\109\112\108\097\116\101 \099\111\110\116\097\105\110\101\114 \119\105\116\104 \110\097\109\101 \037\113 \105\110 \037\113"):format(I:GetFullName(),G))end return Q end return I


local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")

local TemplateContainerUtils = {}

function TemplateContainerUtils.reparentFromWorkspaceIfNeeded(parent, name)
	assert(typeof(parent) == "Instance", "Bad parent")
	assert(type(name) == "string", "Bad name")

	local workspaceContainer = Workspace:FindFirstChild(name)
	local parentedContainer = parent:FindFirstChild(name)
	if workspaceContainer then
		if parentedContainer then
			error(("Duplicate container in %q and %q"):format(
				workspaceContainer:GetFullName(),
				parentedContainer:GetFullName()))
		end

		-- Reparent
		if RunService:IsRunning() then
			workspaceContainer.Parent = parent
		end

		return workspaceContainer
	end

	if not parentedContainer then
		error(("No template container with name %q in %q")
			:format(parent:GetFullName(), name))
	end

	return parentedContainer
end

return TemplateContainerUtils
