Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

[STILL UNANSWERED] EXP Debounce is not working, can someone tell me why?

Asked by 2 years ago
Edited 2 years ago

the thing i need help with is pretty easy, its just how to do so players cant spam the EXP getting, i tried adding debounce but its not working, help?

local debounce = false
local Spirit = script.Parent
 Spirit.Touched:connect(function(entity)
     if entity.Parent.Name == "WaterEssence" and game.Players:FindFirstChild(entity.Parent.Parent.Name)and debounce == false then
        local Man =  entity.Parent.Parent.Parent
        local RealMan = game.Players:FindFirstChild(entity.Parent.Parent.Name)
        local Bro = RealMan:FindFirstChild("leaderstats")
        local EXP = Bro:FindFirstChild("EXP")
        EXP.Value = EXP.Value + 10
        print(EXP.Value)
        local debounce = true
        wait(20) 
        local debounce = false                
     end
 end)

thanks

EDIT think i found the problem, maybe its because at the start of the script it says "local debounce = false" so maybe anytime i run the script it goes back to false. can someone tell me how to fix this?

0
Is the problem that the players can still get xp or that they can't get xp at all. justoboy13 153 — 2y
0
replace "local debounce" with just "debounce" in the function only. RubenKan 3590 — 2y

2 answers

Log in to vote
0
Answered by
522049 152
2 years ago

Move local debounce = true to line 5 so it runs before you give EXP and see if that helps.

Ad
Log in to vote
0
Answered by 2 years ago

You should move debounce = true to between lines four and five. Your debounce will only work for one second after your 20 second delay, because the if statement will keep returning true until debounce is true, which you do after your delay. Good luck!

0
still not working SuperBeeperman 30 — 2y
0
Try removing local from the beginning of debounce, everywhere except on line one. Combine that with the explanation above, and your script should work fine. ThatPreston 338 — 2y

Answer this question