I'm trying to make a "hitbox" that stops taking health when you step out of it, though when you step out of it, it just keeps taking health, any solutions? here is my script:
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then while hit.Parent.Humanoid do hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1 wait() end end end)
local dealdamage = false script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and not dealdamage then dealdamage = true while hit.Parent.Humanoid do if dealdamage then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1 else break; end wait() end end end) script.Parent.TouchEnded:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then dealdamage = false; end end)
Basically this script will deal damage when the player touches the part and then stop dealing damage once the player steps off the part. Also, you might want to think about lowering the damage you're dealing to the player. 1 might kill the player a little fast.