Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

it doesn't wait 1 second before touching again?

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

✓ Accepted answer

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)

2 comments

0

so yea it works

0

it didnt work before because the value clicked was being set in the function, therefore making the debounce false again

This discussion is preserved as it was. New answers, comments, and votes are closed.