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

How to detect if an NPC is dead?

I'm working on a game, and I'm making the final boss. I want it so when the boss dies, it awards a badge. Problem is, I'm terrible at scripting and it's not working as intended, though I've referenced many wiki pages.

local humanoid = script.Parent
local BadgeService = game:GetService("BadgeService")
while true do
	if humanoid.Health < 1 then
		BadgeService:AwardBadge(2124549136)
		print ("Beat Game")
	end
end

Additional info: Localscript inside of Humanoid of an NPC If you could help, it would be greatly appreciated.

1 comment

0

Your while loop will hang, causing a crash. You can simply just use a yielding signal: Humanoid.Died

1 answer

✓ Accepted answer

instead of constantly checking you can bind an event like

humanoid.Died:Connect(function()
	BadgeService:AwardBadge(2124549136)       
	print ("Beat Game")
end)

also you probably want to make it a server script

1 comment

0

on top of this you need to put a player id as the second parameter in awardbadge so the game knows who to award

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