To make everything clear, i don't want it to run just once. I want it to run non-stop while the player is touching the part and stop when he's not.
function onTouch(part) local check = part.Parent:FindFirstChild("Humanoid") while check ~= nil do wait(1) check.Parent.Humanoid.Health = check.Parent.Humanoid.Health - 1 end end script.Parent.Touched:connect(onTouch)
I'm keeping tract of who's touching the part and running through them to damage.
local part=--part local touching={} local running=false function has() if running==false then running=true while #touching>0 do for _,v in pairs(touching) do if v:FindFirstChild("Humanoid") then v.Humanoid:TakeDamage(10) end end wait() end running=false end end part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local good=true for _,v in pairs(touching) do if v==hit.Parent then good=false end end if good then table.insert(touching,hit.Parent) has() end end end) part.TouchEnded:Connect(function(hit) for i,v in pairs(touching) do if v==hit.Parent then table.remove(touching,i) end end end)
if script.Parent.Touched then function () --ur code here end end