Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make script pause after executing (clone)?

Hello I am currently trying to make a script that spawns an infinite track. It works well except that it spawns tons and tons of models when it is touched. How do I pause the script momentarily to prevent this?

local function clone()
	local cloned = road:Clone()
	cloned.Parent = game.Workspace
	--cloned:SetPrimaryPartCFrame(CFrame.new(0, 0, 130.588))--(0, 0, 130.588)
	--cloned:SetPrimaryPartCFrame(PreviousPart.PrimaryPart.CFrame * CFrame.new(0, 0, 130.588))--(0, 0, 130.588)
	cloned:SetPrimaryPartCFrame(road.PrimaryPart.CFrame * CFrame.new(0,0,-130.588))
	print("road has spawned")
end

--EVENT
touch.Touched:Connect(clone)

Thanks in advance :)

1 answer

✓ Accepted answer

Use a debounce.

local debounce = true -- tells if cloning is available
local function clone()
	if debounce == true then -- if cloning is available
		debounce = false -- makes cloning unavailable
		local cloned = road:Clone()
		cloned.Parent = workspace
--		cloned:PivotTo(CFrame.new(0, 0, 130.588))--(0, 0, 130.588)
--		cloned:PivotTo(PreviousPart:GetPivot() * CFrame.new(0, 0, 130.588))--(0, 0, 130.588)
		cloned:PivotTo(road:GetPivot() * CFrame.new(0,0,-130.588))
		print("road has spawned")
		task.wait(5) -- after 5 seconds
		debounce = true -- makes it available again
	end
end

--EVENT
touch.Touched:Connect(clone)

This discussion is preserved as it was. New answers, comments, and votes are closed.