Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if an NPC is dead?

Asked by 4 years ago

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.

0
Your while loop will hang, causing a crash. You can simply just use a yielding signal: Humanoid.Died Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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 Gameplayer365247v2 1055 — 4y
Ad

Answer this question