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.
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)
local damage = 10 local touched local timebeforeotherdamage = 2 script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if touched == false then touched = true repeat if touched == true then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage end wait(timebeforeotherdamage) until hit.Parent.Humanoid.Health == 0 end end repeat wait() until touched == false end) script.Parent.TouchEnded:Connect(function(hit) touched = false end)