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

while true do loop does not break when boss npc is dead?

I made an escape game with a boss in it. When you defeat the boss, a blue portal should open up in the boss-fighting room. But it didn't. I tried using a while true do and repeat until loops so that the portal could appear but it does not. It does not even print the words into the command output when it is defeated, it just continues to print "Alive".

Code:

local health = game:GetService("Workspace").TS4.bossnpc.Humanoid.Health

game:GetService("ReplicatedStorage").Timesplitters.BossAppear.Event:Connect(function()
	while health > 0 do
		wait(1)
		print("Alive")
		if health <= 0 then
			game:GetService("ReplicatedStorage").Timesplitters.BossLose:Fire()
			print("Fired!")
			break
		end
	end
end)

1 answer

✓ Accepted answer

Try using the Humanoid.Died event instead

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