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

Debounce not working?

I have a script in this thing you're supposed to grab like a coin, where it disappears slowly when you touch it and also makes an achievement sound. The problem is that if you touch it more than once, somehow the debounce doesn't stop the function from overlapping, so it disappears almost instantly instead of taking two whole seconds. Is there something wrong with the placement of debounce?

debounce=false
function Spud(g)
	if g.Parent:findFirstChild("Humanoid") and debounce==false then
		debounce=true
		script.Parent.Sound:play()
		for i=1,20 do
			local p=script.Parent
			p.Position=Vector3.new(p.Position.x,p.Position.y+0.15,p.Position.z)
			p.Transparency=p.Transparency+0.05
			p.Mesh.Scale=Vector3.new(p.Mesh.Scale.x+0.1,p.Mesh.Scale.y+0.1,p.Mesh.Scale.z+0.1)
			wait(0.1)
		end
	end
	debounce=false
	script.Parent:Destroy()
end

script.Parent.Touched:connect(Spud)

1 comment

1

Part of the Debounce is Outside of the 'if' statement, Line 14.

1 answer

✓ Accepted answer

If you use a bool value for "debounce," it will work. Tested and it works.

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