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

Why is Ting/Debounce only working first time through script?

Asked by 4 years ago

So this is a basic take damage script. Because of how often players can hit stuff, even 1 damage is op without a ting/debounce. Well so i put in one, and the results are funky.. I upped the ting time for testing reasons. I got hit once, waited 20 seconds, and then I was able to get hit as many times as i wanted, as if ting didn't exist anymore after the first touch.. I even printed ting and it always came back as 1..

Anyone know why?

local touch = script.Parent:FindFirstChild("Head")


local ting = 0 

function dmg(hit)
    if ting == 0 then
    ting = 1
    if hit.Parent ~= nil then
        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil then
            hum.Health = hum.Health - math.random(12,20)
        end
        end
    end
    wait(20) -- Here is my wait between activations
    ting = 0
end

touch.Touched:connect(dmg)

1 answer

Log in to vote
0
Answered by 4 years ago

Nevermind, I'm just tired I guess.

For anyone who wants a working damage script

local touch = script.Parent:FindFirstChild("Head")


local ting = 0 

function dmg(hit)
    if ting == 0 then
     if hit.Parent ~= nil then
        local hum = hit.Parent:findFirstChild("Humanoid")
            if hum ~= nil then
            ting = 1
            hum.Health = hum.Health - math.random(12,20)
            wait(1)
            ting = 0
            end
     end
    end
end
touch.Touched:connect(dmg)
Ad

Answer this question