I want to make a button slowly kill a player, but when they exit a radius, they will stop taking damage. Here is the code that I'm using to get a button to slowly kill a player:
clickDetector.MouseClick:Connect(function() local h = hit.Parent:findFirstChild("Humanoid") while true do if (h ~= nil) then h.Health = h.Health - 2 wait(1) end end end)
But I still need to find a way on how to make it so that it stops after the player leaves a certain radius. What functions and services (and such) would I use?
if im getting you right, this is what you want?
clickDetector.MouseClick:Connect(function() local healthrange = --what health you want them to end up with local h = hit.Parent:findFirstChild("Humanoid") repeat if (h ~= nil) then h.Health = h.Health - 2 wait(1) until h.Health == healthrange end end)