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 :)
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)