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

How would I add debounce to this click detector script?

Asked by 3 years ago

I'm very new to scripting, here is the script

clickDetector = game.workspace.Box.top.ClickDetector

function onMouseClick() game.Workspace.Box.bottom.Transparency = 0 game.Workspace.Box.top.Transparency = 1

        local num = math.random(1,5)

        if num == 1 then

            print("1")

        elseif num == 2 then

            print("2")

        elseif num == 3 then

            print("3")

        elseif num == 4 then

            print("4")

        elseif num == 5 then

            print("5")

    end
wait(3)
game.Workspace.Box.bottom.Transparency = 1
game.Workspace.Box.top.Transparency = 0

end clickDetector.MouseClick:connect(onMouseClick)

0
not sure why it broke the script up into different areas ^ MegaKeegan5375 0 — 3y

1 answer

Log in to vote
0
Answered by
Y_VRN 246 Moderation Voter
3 years ago

It us fairly easy to make a debounce:

clickDetector = game.workspace.Box.top.ClickDetector

loal debounce = true

function onMouseClick() 
if debounce then
debounce = false
game.Workspace.Box.bottom.Transparency = 0 game.Workspace.Box.top.Transparency = 1

            local num = math.random(1,5)

            if num == 1 then

                print("1")

            elseif num == 2 then

                print("2")

            elseif num == 3 then

                print("3")

            elseif num == 4 then

                print("4")

            elseif num == 5 then

                print("5")

        end
    wait(3)
    game.Workspace.Box.bottom.Transparency = 1
    game.Workspace.Box.top.Transparency = 0
    debounce = true
    end
end clickDetector.MouseClick:connect(onMouseClick)

Please note, I wrote this answer on mobile after waking up, so if there is any problem with this please tell me.

0
thank you so much MegaKeegan5375 0 — 3y
0
No problem. Y_VRN 246 — 3y
0
Accepted for you; they left you on read lmfao. Ziffixture 6913 — 3y
0
@Ziffixture Thanks for the accept! Y_VRN 246 — 3y
Ad

Answer this question