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

How do i check if my npc is dead? I tried alot of things but none worked

Asked by 5 years ago

****so im making a game where once u beat the final boss a cutscene will play but i dont know how to check if the npc boss is dead. I tried if script.Parent.Humanoid.Health == 0 then --- play the cutscene end but it doesnt work. help?****

0
Did you add a code that constantly checks if it dies or not? Like a Function or a loop? TheJellyNinja_XD13 62 — 5y
0
script.Parent.Humanoid.Died DeceptiveCaster 3761 — 5y
0
look through the studio object browser next time before you ask a question like this DeceptiveCaster 3761 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

This should work, I'm pretty sure the died function isn't deprecated.

local character = script.Parent
character:WaitForChild("Humanoid").Died:Connect(function()
print(character.Name .. " has died!")
end)
Ad
Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

You need to use HUMANOID.Died

here is page on wiki: Humanoid.Died - Wiki

Here is a example:


local npc_humanID = script.Parent:WaitForChild("Humanoid") npc_humanID.Died:Connect(function() print("The npc " .. script.Parent.Name .. " died!") end)

for play cutscene:

local npc_humanID = script.Parent:WaitForChild("Humanoid")

npc_humanID.Died:Connect(function()
    local cutscene = game:GetService("ReplicatedStorage").Cutscene -- Cutscene Location
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.Character ~= nil then
            cutscene:Clone().Parent = v.Character
        end
    end
end)

Hope it helped :)

Errors? tell-me on comments.

0
ok so i tried both solutions but the cutscene will only play once i die? nzsalty16 81 — 5y
0
You logically should do the script for the cutscene. and it was only going to start when the npc dies. I'll add an option for the cutscene to start. yHasteeD 1819 — 5y
0
added function for when the npc die start the cutscene. yHasteeD 1819 — 5y
0
Thanks! nzsalty16 81 — 5y

Answer this question