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

how would i use debounce in this situation?

Asked by 6 years ago

how would i use debounce in this situtation? ive looked on the wiki and it doesnt make much sense to me. Also how would i be able to make it so if someone clicked they would have to wait a few seconds before they can click again? i dont think im doing it right

local mouse = game.Players.LocalPlayer:GetMouse()
local clicks = 0
    wait(5)
    mouse.Button1Down:connect(function()
            clicks = clicks + 1
    if clicks == 3 then 
        for i = 1,1 do
local Leaderstats = game.Players.LocalPlayer.leaderstats:findFirstChild("Strength")
            if Leaderstats ~= nil then
                for i = 1,1 do
                Leaderstats.Value = Leaderstats.Value + 1
                wait(5)
                clicks = 0

                        end
                    end
                end
            end
        end
end)

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

pss, your script looks messy cause your not using indents right ;p

Ok so to make a debounce we are going to create a bool variable outside this mess, then with they click check if it is true, if so make it false, at the end of the click event we wait a few seconds then make it true again.

local mouse = game.Players.LocalPlayer:GetMouse()
local clicks = 0
local d = true 

wait(5)

mouse.Button1Down:connect(function()
    if d==true then d=false --debounce
        clicks = clicks + 1
        if clicks == 3 then 
            for i = 1,1 do
                local Leaderstats = game.Players.LocalPlayer.leaderstats:findFirstChild("Strength")
                if Leaderstats ~= nil then
                    for i = 1,1 do
                        Leaderstats.Value = Leaderstats.Value + 1
                        clicks = 0
                    end
                end
            end
        end
    end
    wait(5) --debounce wait
    d=true --change back
end)
0
You could just do "if d then d = false". Also, "findFirstChild" is deprecated, use "FindFirstChild". hiimgoodpack 2009 — 6y
0
@hiimgoodpack tis a habit of mine DanzLua 2879 — 6y
Ad

Answer this question