01 | function damageplr(hit) |
02 | wait( 1.0 ) |
03 | if hit.Parent.Head then |
04 | hit.Parent:FindFirstChild( "Humanoid" ).Health = hit.Parent:FindFirstChild( "Humanoid" ).Health - 2 |
05 | end |
06 | end |
07 |
08 | function TouchEnd(hit) |
09 |
10 | end |
11 |
12 | script.Parent.Touched:connect( function (hit) |
13 | wait() |
14 | repeat damageplr() until TouchEnd() |
15 | hit.Anchored = false |
16 | end ) |
17 |
18 | script.Parent.TouchEnded:connect(TouchEnd) |
19 | script.Parent.Touched:connect(damageplr) |
This script will stop doing damage once the player gets inside the part.
01 | local CanTouch = true |
02 | script.Parent.Touched:Connect( function (part) |
03 | local hum = part.Parent:FindFirstChild( "Humanoid" ) |
04 | if CanTouch and hum then |
05 | CanTouch = false |
06 | repeat |
07 | hum.Health = hum.Health - 10 |
08 | wait( 1 ) |
09 | until hum.health = 0 |
10 | CanTouch = true |
11 | end |
12 | end ) |
This one kinda works but once the player leaves it continues doing damage, because of until hum.Health = 0
I know this code sucks, but I'm a beginner coder.
I Think it has to do with the second script line 9 when using Until you Should Use double equal signs, so Instead Of "Until hum.Health = 0" do "Until hum.Health == 0"
look try this sorry if doesnt work but i tried my best! edit: there was a mistake so i had to edit it(should work properly now)
01 | local damage = 10 |
02 | local touched |
03 | local timebeforeotherdamage = 2 |
04 |
05 |
06 |
07 | script.Parent.Touched:Connect( function (hit) |
08 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
09 | if touched = = false then |
10 | touched = true |
11 | repeat |
12 | if touched = = true then |
13 | hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage |
14 |
15 | end |