Clone() Is Spawning MULTIPLE Clones

What is up with the clone function? Did it get deprecated or something?

Whenever I step on the block, It false and whatnot but then, when I clone it it spawns like 5 different clones-

script.Parent.Touched:Connect(function()
	task.wait(2)
	local Clone = script.Parent:Clone()
	Clone.Parent = game.Workspace
	Clone.Anchored = true
	Clone.Transparency = 1
	Clone.CanCollide = false
	task.wait(0.3)
	script.Parent.Anchored = false
	
	wait(5)
	Clone.Transparency = 0
	Clone.CanCollide = true
	
	wait(20)
	script.Parent:Destroy()
end)
1 Like

maybe the touched event fires multiple times, try adding a debounce

2 Likes

Add a cooldown its cloning multiple times

3 Likes

for one clone(not more) use

--i wait for the event to fire once. once fired it will not do it again
script.Parent.Touched:Wait()
-- exactly your code
task.wait(2)
	local Clone = script.Parent:Clone()
	Clone.Parent = game.Workspace
	Clone.Anchored = true
	Clone.Transparency = 1
	Clone.CanCollide = false
	task.wait(0.3)
	script.Parent.Anchored = false
	
	wait(5)
	Clone.Transparency = 0
	Clone.CanCollide = true
	
	wait(20)
	script.Parent:Destroy()

ok i did it @StarJ3M

1 Like

This —, but can you mind explaining the code using some comments?

kinda

This should work (I added a debounce)

local debounce = true

script.Parent.Touched:Connect(function()
if debounce == true then -- check if debounce is true
debounce = false -- set the debounce to false
	task.wait(2)
	local Clone = script.Parent:Clone()
	Clone.Parent = game.Workspace
	Clone.Anchored = true
	Clone.Transparency = 1
	Clone.CanCollide = false
	task.wait(0.3)
	script.Parent.Anchored = false
	
	wait(5)
	Clone.Transparency = 0
	Clone.CanCollide = true
	
	wait(20)
   debounce = true  -- set the debounce back to true
	script.Parent:Destroy()
end
end)
1 Like

Still again, Kinda works because legit the new blocks generated will automatically fall

then set the Clone’s Anchored property to true using

Clone.Anchored = true

then unanchor it when needed.

Sorry if I didn’t understand correctly you just make 0 sense

Its already inside of the script that its anchored, why would I need to replace/delete this?

The Clone() event spawns multiple clones because the part is constantly being touched by another object or a player. Try adding a debounce/cooldown to it.

local debounce = false

script.Parent.Touched:Connect(function()
	if debounce then
		return
	end
	debounce = true
	local Clone = script.Parent:Clone()
	Clone.Parent = game.Workspace
	Clone.Anchored = true
	Clone.Transparency = 1
	Clone.CanCollide = false
	script.Parent.Anchored = false
	task.wait(5)
	Clone.Transparency = 0
	Clone.CanCollide = true
	task.wait(20)
	script.Parent:Destroy()
	debounce = false
end)

Just add a debounce to prevent the function being executed too frequently. Touched fires several times even if you think it should only fire once.