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

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

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?

3 comments

0

Did you add a code that constantly checks if it dies or not? Like a Function or a loop?

0

script.Parent.Humanoid.Died

0

look through the studio object browser next time before you ask a question like this

2 answers

✓ Accepted answer

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)

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.

4 comments

0

ok so i tried both solutions but the cutscene will only play once i die?

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.

0

added function for when the npc die start the cutscene.

0

Thanks!

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