Npc custom dead animation, didnt work

soo i wanted to make Custom npc when dead but ti doesnt work
i’ve tried changing from health change to 0, or if humanoid.died , still didnt work

local Humanoid = script.Parent.Parent.Parent.Parent.Humanoid

Humanoid.HealthChanged:Connect(function(Health)
	if Health <= 0 then
		print("Died")
		--thigs thatll happen
	end
end)

yes i just wanted the animation to rotate an image from the torso

3 Likes

try this let me know if this works

local TweenService = game:GetService("TweenService")

local humanoid = script.Parent.Parent.Parent.Parent:FindFirstChildOfClass("Humanoid")
local torso = humanoid and humanoid.Parent:FindFirstChild("Torso")
local billboardGui = torso and torso:FindFirstChildOfClass("BillboardGui")
local img = billboardGui and billboardGui:FindFirstChildOfClass("ImageLabel")

if humanoid and img then
    humanoid.HealthChanged:Connect(function(health)
        if health <= 0 then
            print("Died")
            local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
            local tween = TweenService:Create(img, tweenInfo, { Rotation = 90 })
            tween:Play()
        end
    end)
else
    warn("Required objects not found.")
end

2 Likes

thx but, its still straight to death, no animation at all :blush:

2 Likes

(its like when healthchange/.Died, didnt giving the npc a chance to animate smth)

add prints through out the script and tell me whats not printing.

print("HI")

So you guys can use Humanoid.Died:Connect(function() instead of HealthChanged

script.Parent.Humanoid.Died:Connect(function()
	print("Rig died")
	--Animation
end)

Its just a script inside of a rig

Try this:

local Humanoid = script.Parent.Parent.Parent.Parent.Humanoid

if Humanoid then
    Humanoid.Died:Connect(function()
        print("Died")
        -- things that'll happen
    end)
else
    warn("Humanoid not found in the parent hierarchy")
end

i think it was this line
gambar
it didnt print the hi0

Buddy use this script inside the rig and it will work:

local humanoid = script.Parent.Humanoid

script.Parent.Humanoid.Died:Connect(function()
	print("Rig died")
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://123"--Your animation ID here
	animation:Destroy()
	local specialMoveTrack = humanoid.Animator:LoadAnimation(animation)
	specialMoveTrack:Play()
end)

thx but still, straight to dead (its like when healthchange/.Died, didnt giving the npc a chance to animate smth)

What? Sorry i dont get what you are trying to say

smh its like when healthchange = 0, it immediately destroys the model/parent, there is no delay like 10 seconds before destroying the model, after healthchange 0 or humanoid.Died

But the rig shouldnt be destroyed its justs dies… If the problem you are facing is the rig parts falling apart just go to the rig humanoid and deactivate BreakJointsOnDeath.

A video or image of the problem would be very helpful lad.

here is some more prints and warns added to your script tell me whats not printing.

local TweenService = game:GetService("TweenService")

local humanoid = script.Parent.Parent.Parent.Parent:FindFirstChildOfClass("Humanoid")
local torso = humanoid and humanoid.Parent:FindFirstChild("Torso")
local billboardGui = torso and torso:FindFirstChildOfClass("BillboardGui")
local img = billboardGui and billboardGui:FindFirstChildOfClass("ImageLabel")

if humanoid and img then
    print("Objects found, starting monitoring")
    humanoid.HealthChanged:Connect(function(health)
        print("Health changed to", health)
        if health <= 0 then
            print("Died")
            if img.Rotation then
                local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
                local tween = TweenService:Create(img, tweenInfo, { Rotation = 90 })
                tween:Play()
                print("Tween started")
            else
                warn("Image label does not have Rotation property")
            end
        end
    end)
else
    warn("Required objects not found.")
end

Why are you using TweenService?

Just a habit I usually prefer using tweenservice

What why is this to do the animation? its not very optimized for what i know…

Did you turn off BreakJointsOnDeath. Don’t see anyone mentioning or asking this.

Edit: Nevermind someone did.