Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to correctly add a Debounce to this script?

Asked by
Gigaset39 111
2 years ago
Edited 2 years ago

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)
0
It works, i just cant get right the Debounce = true thing. Gigaset39 111 — 2y

1 answer

Log in to vote
1
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
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)
0
Finally i can finish my game,Thanks. Gigaset39 111 — 2y
Ad

Answer this question