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

it doesn't wait 1 second before touching again?

Asked by
imKlevi 94
4 years ago

it doesn't wait 1 second before touching again. Whats wrong ?

workspace[plr.Name.."Skills"].BallAttack.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    local clicked = false
    if hum and clicked == false then
        clicked = true
        hum:TakeDamage(10)
        print("Killing!")
        wait(1)
        clicked = false
    end
end)

1 answer

Log in to vote
1
Answered by
RAFA1608 543 Moderation Voter
4 years ago

The local value clicked is stored within the function's scope, meaning that it will not wait 1 second because every time the function is ran, it is set to be false, or something (i suck at explaining stuff.). Heres the fixed version:

clicked = false
workspace[plr.Name.."Skills"].BallAttack.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if hum and clicked == false then
        clicked = true
        hum:TakeDamage(10)
        print("Killing!")
        wait(1)
        clicked = false
    end
end)
0
so yea it works imKlevi 94 — 4y
0
it didnt work before because the value clicked was being set in the function, therefore making the debounce false again RAFA1608 543 — 4y
Ad

Answer this question