local q=script.Parent.BounceTemplate local r=false local w={}function w.isBounceTemplate(q)return q:GetAttribute("\073\115\066\111\117\110\099\101\084\101\109\112\108\097\116\101",true)==true end function w.getTarget(q)if not w.isBounceTemplate(q)then return nil end if q:IsA("\079\098\106\101\099\116\086\097\108\117\101")then return q.Value else local r=q:FindFirstChild("\066\111\117\110\099\101\084\097\114\103\101\116")if r then return r.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 w.create(B,E)assert(typeof(B)=="\073\110\115\116\097\110\099\101","\066\097\100 \116\097\114\103\101\116")assert(type(E)=="\115\116\114\105\110\103","\066\097\100 \108\105\110\107\078\097\109\101")if r then return w.createLink(B,E)end local v=q:Clone()v:SetAttribute("\073\115\066\111\117\110\099\101\084\101\109\112\108\097\116\101",true)v.Name=E local Z=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")Z.Name="\066\111\117\110\099\101\084\097\114\103\101\116"Z.Value=B Z.Parent=v return v end function w.createLink(q,r)assert(typeof(q)=="\073\110\115\116\097\110\099\101","\066\097\100 \116\097\114\103\101\116")assert(type(r)=="\115\116\114\105\110\103","\066\097\100 \108\105\110\107\078\097\109\101")local w=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")w.Name=r w.Value=q w:SetAttribute("\073\115\066\111\117\110\099\101\084\101\109\112\108\097\116\101",true)return w end return w
--[=[
	@class BounceTemplateUtils
	@private
]=]

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
