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?
01 | local touch = script.Parent:FindFirstChild( "Head" ) |
02 |
03 |
04 | local ting = 0 |
05 |
06 | function dmg(hit) |
07 | if ting = = 0 then |
08 | ting = 1 |
09 | if hit.Parent ~ = nil then |
10 | local hum = hit.Parent:findFirstChild( "Humanoid" ) |
11 | if hum ~ = nil then |
12 | hum.Health = hum.Health - math.random( 12 , 20 ) |
13 | end |
14 | end |
15 | end |
16 | wait( 20 ) -- Here is my wait between activations |
17 | ting = 0 |
18 | end |
19 |
20 | touch.Touched:connect(dmg) |
Nevermind, I'm just tired I guess.
For anyone who wants a working damage script
01 | local touch = script.Parent:FindFirstChild( "Head" ) |
02 |
03 |
04 | local ting = 0 |
05 |
06 | function dmg(hit) |
07 | if ting = = 0 then |
08 | if hit.Parent ~ = nil then |
09 | local hum = hit.Parent:findFirstChild( "Humanoid" ) |
10 | if hum ~ = nil then |
11 | ting = 1 |
12 | hum.Health = hum.Health - math.random( 12 , 20 ) |
13 | wait( 1 ) |
14 | ting = 0 |
15 | end |
16 | end |
17 | end |
18 | end |
19 | touch.Touched:connect(dmg) |