I was making a part that deals damage but since roblox runs at lots of ticks per second, the damage is too frequent for me to use like i wish to use it. I need help finding a way to delay the frequency of the damage i take to an amount of seconds that i choose.
Here's my damage script:
1 | local part = --reminder to do this |
2 |
3 | part.Touched:connect( function (hit) |
4 | if hit.Parent and hit.Parent:FindFirstChild( "Humanoid" ) then |
5 | hit.Parent.Humanoid:TakeDamage( 1 ) |
6 | end |
7 | end ) |
I assume you want to use what we in the biz call debounce
01 | local go = true |
02 |
03 | part.Touched:Connect( function (hit) |
04 | if go then |
05 | go = false |
06 | --We set go to false, so that if this event is fired before we set it to true after a second |
07 | --It won't get through the if statement |
08 |
09 | print ( "Code here" ) |
10 |
11 | wait( 1 ) |
12 | go = true |
13 | end |
14 | end |
Put a wait() Something like,
1 | part.Touched:connect( function (hit) |
2 | if hit.Parent and hit.Parent:FindFirstChild( "Humanoid" ) then |
3 | wait( 5 ) --time it will wait in seconds |
4 | hit.Parent.Humanoid:TakeDamage( 1 ) |
5 | end |
6 | end |
Sorry if I messed up, I'm on mobile