local t=script.Parent.BounceTemplate local K=false local s={}function s.isBounceTemplate(t)return t:GetAttribute("\073\115\066\111\117\110\099\101\084\101\109\112\108\097\116\101",true)==true end function s.getTarget(t)if not s.isBounceTemplate(t)then return nil end if t:IsA("\079\098\106\101\099\116\086\097\108\117\101")then return t.Value else local K=t:FindFirstChild("\066\111\117\110\099\101\084\097\114\103\101\116")if K then return K.Value else warn("\091\066\111\117\110\099\101\084\101\109\112\108\097\116\101\085\116\105\108\115\046\103\101\116\084\097\114\103\101\116\093 - \066\111\117\110\099\101 \116\101\109\112\108\097\116\101 \119\105\116\104\111\117\116 \066\111\117\110\099\101\084\097\114\103\101\116")return nil end end end function s.create(o,a)assert(typeof(o)=="\073\110\115\116\097\110\099\101","\066\097\100 \116\097\114\103\101\116")assert(type(a)=="\115\116\114\105\110\103","\066\097\100 \108\105\110\107\078\097\109\101")if K then return s.createLink(o,a)end local j=t:Clone()j:SetAttribute("\073\115\066\111\117\110\099\101\084\101\109\112\108\097\116\101",true)j.Name=a local q=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")q.Name="\066\111\117\110\099\101\084\097\114\103\101\116"q.Value=o q.Parent=j return j end function s.createLink(t,K)assert(typeof(t)=="\073\110\115\116\097\110\099\101","\066\097\100 \116\097\114\103\101\116")assert(type(K)=="\115\116\114\105\110\103","\066\097\100 \108\105\110\107\078\097\109\101")local s=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")s.Name=K s.Value=t s:SetAttribute("\073\115\066\111\117\110\099\101\084\101\109\112\108\097\116\101",true)return s end return s


local BounceTemplate = script.Parent.BounceTemplate

local CREATE_ONLY_LINK = false

local BounceTemplateUtils = {}

function BounceTemplateUtils.isBounceTemplate(instance)
	return instance:GetAttribute("IsBounceTemplate", true) == true
end

function BounceTemplateUtils.getTarget(instance)
	if not BounceTemplateUtils.isBounceTemplate(instance) then
		return nil
	end

	if instance:IsA("ObjectValue") then
		return instance.Value
	else
		local found = instance:FindFirstChild("BounceTarget")
		if found then
			return found.Value
		else
			warn("[BounceTemplateUtils.getTarget] - Bounce template without BounceTarget")
			return nil
		end
	end
end

function BounceTemplateUtils.create(target, linkName)
	assert(typeof(target) == "Instance", "Bad target")
	assert(type(linkName) == "string", "Bad linkName")

	if CREATE_ONLY_LINK then
		return BounceTemplateUtils.createLink(target, linkName)
	end

	local copy = BounceTemplate:Clone()
	copy:SetAttribute("IsBounceTemplate", true)
	copy.Name = linkName

	local objectValue = Instance.new("ObjectValue")
	objectValue.Name = "BounceTarget"
	objectValue.Value = target
	objectValue.Parent = copy

	return copy
end

function BounceTemplateUtils.createLink(target, linkName)
	assert(typeof(target) == "Instance", "Bad target")
	assert(type(linkName) == "string", "Bad linkName")

	local objectValue = Instance.new("ObjectValue")
	objectValue.Name = linkName
	objectValue.Value = target
	objectValue:SetAttribute("IsBounceTemplate", true)

	return objectValue
end

return BounceTemplateUtils
