Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a button slowly kill a player? (More info in desc.)

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?

2 comments

0

on a mouse click. it goes player and then character. so you would do local h = plr.Character:findFirstChild('Humanoid') In the parameters you would put plr

0

If you got the health decreasing and whatnot and just asking for the radius then I would suggest either using magnitude which can be difficult to use at times or use some other thing

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.