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

How do I end a loop if the person gets off the heal pad?

-- RandyN56 2/1/21

--[[INSTRUCTIONS: Put this script inside of a block, surround your fighting mat with this, make it invisible, 
cancollide off. ]]--




local Healblock = script.Parent

Healblock.Touched:Connect(function(hit)
	local Hum = hit.Parent:FindFirstChild("Humanoid")
	if Hum then
		for i = 0,100,.05 do
			wait()
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health + i
			if hit.Parent.Humanoid.health == 100 or not hit.Parent:FindFirstChild("Humanoid") then break

			end
		end
	end
end)

Big cheers to whoever has time to help

1 answer

This isn’t what mossy is paying you for

Seriously though; Break only works on while loops. I fixed your script:


-- RandyN56 2/1/21

--[[INSTRUCTIONS: Put this script inside of a block, surround your fighting mat with this, make it invisible, 
cancollide off. ]]--

local Healblock = script.Parent

Healblock.Touched:Connect(function(hit)
    local Hum = hit.Parent:FindFirstChild("Humanoid")
    if Hum then
     while true do 
        for i = 0,100,.05 do
            wait()
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health + i
            if hit.Parent.Humanoid.health == 100 then 
               break
          end
        end
    end
end)

LMK if it works.

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