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

How to correctly add a Debounce to this script?

Hi, i took a ”regeneration button” from ToolBox, and i tried to add a Debounce thing, soo you cant spam that button, but i still cant get it right, can someone help?

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

function onClicked()

local back = save:clone()
back.Parent = location
back:MakeJoints()
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 comment

0

It works, i just cant get right the Debounce = true thing.

1 answer

✓ Accepted answer
location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()
local Debounce = false
function onClicked()
	if not Debounce then
		Debounce = true
		local back = save:clone()
		back.Parent = location
		back:MakeJoints()
		wait(1)
		Debounce = false
	end
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 comment

0

Finally i can finish my game,Thanks.

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