function damageplr(hit)
wait(1.0)
if hit.Parent.Head then
hit.Parent:FindFirstChild("Humanoid").Health =hit.Parent:FindFirstChild("Humanoid").Health - 2
end
end
function TouchEnd(hit)
end
script.Parent.Touched:connect(function(hit)
wait()
repeat damageplr() until TouchEnd()
hit.Anchored = false
end)
script.Parent.TouchEnded:connect(TouchEnd)
script.Parent.Touched:connect(damageplr)
This script will stop doing damage once the player gets inside the part.
local CanTouch = true
script.Parent.Touched:Connect(function(part)
local hum = part.Parent:FindFirstChild("Humanoid")
if CanTouch and hum then
CanTouch = false
repeat
hum.Health = hum.Health - 10
wait(1)
until hum.health = 0
CanTouch = true
end
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.

1 comment
This probably isn't the best solution, but every time you wanna do damage, you can see if the Player's position is within a certain coordinate bound, this solution really only works well if the part is rectangular and is harder to calculate otherwise.