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

Why doesn't this work?

This script is inside a NPC, that has a humanoid called Enemy. The problem is when he dies he just dies. My script is supposed to make him play an Animation, but it doesn't work. It only works in roblox studio, but not in game.

local dead = false

script.Parent.Enemy.Changed:connect(function()
		if script.Parent.Enemy.Health <= 0 and dead == false then
		script.Parent.Enemy.Health = 100
		dead = true
		script.Parent.Enemy.WalkSpeed = 0
		script.Parent.Attack.Disabled = true -- other script
		script.Parent.Damager.Disabled = true -- other script
		script.Parent.Follow.Disabled = true -- other script
		local Ded = script.Parent.Enemy:LoadAnimation(script.Parent.Die)
		Ded:Play()
		wait(2)
		script.Parent.Enemy.Health = 0
	end
end)

1 answer

✓ Accepted answer

I'm not completely sure, but since it has a Humanoid, it has its own Died event. Whenever its Health goes below 0, ROBLOX breaks all joints. You should have a NumberValue instead of relying on a humanoid (Still good if you are moving it)

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