Animations stop working after player dies

So recently i make a script that runs an animation when a tool is activated but when a player dies, the animation stops working. Here’s the script:

local Tool = script.Parent
local Player = game.Players.LocalPlayer -- Get local player
local Chr = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Chr:WaitForChild("Humanoid")
local debounce = true

while Humanoid and not Humanoid:IsDescendantOf(workspace) do
	Humanoid.AncestryChanged:Wait()
end

local Animation = Tool.Animation
local Animator = Humanoid:WaitForChild("Animator")
local AnimTrack = Animator:LoadAnimation(Animation)

Tool.Activated:Connect(function()
	if debounce then-- Mouse is NOT passed, that's Equipped
		AnimTrack:Play()
		debounce = false
		wait(1)
		debounce = true
	end
end)

Is something wrong with the script? I don’t understand why it stops working after a player dies. :frowning:

2 Likes

There are probably 2 reasons. One reason is because the character’s BreaksJointOnDeath is set to true. Another reason is because you have a ragdoll script, I think. I don’t think there is something wrong with the script.

2 Likes

Yes, i do have a ragdoll script included in the tool, when it hits a player it ragdolls them. How can i fix the issue?

1 Like

May you provide a ragdoll script for this?

1 Like

I can send you the whole tool script for you to take a look, wich is what i think would do best so you can analyse the situation, is that ok with you?

1 Like

Yep, that’s fine with me, I’m ok with that.

1 Like

Alright, it’s night time for me so I’m telling this short.

You should have a Tool.Equipped event for the script to know when do u trigger it. Inside of the Equipped event, put Tool:Activated() function to tell the script that Activated only work when a tool is equipped. Then do the same thing for Activated event. If it still doesnt work, try putting prints in certain parts of the script to check what’s not working. I have no clue what were u trying to do in the “while Humanoid” and changing debounce vars in tool.activated

1 Like

I already helped him fixed it, but he gave a solution in my message without telling the main post about it.

1 Like

Try this one:

local Tool = script.Parent
local Player = game.Players.LocalPlayer -- Get local player
local Chr = Player.Character
if Chr == nil or Chr.Parent ~= game:GetService("Workspace") then
	Chr = Player.CharacterAdded:Wait()
end
local Humanoid = Chr:WaitForChild("Humanoid")
local debounce = true

while Humanoid and not Humanoid:IsDescendantOf(workspace) do
	Humanoid.AncestryChanged:Wait()
end

local Animation = Tool.Animation
local Animator = Humanoid:WaitForChild("Animator")
local AnimTrack = Animator:LoadAnimation(Animation)

Tool.Activated:Connect(function()
	if debounce then-- Mouse is NOT passed, that's Equipped
		AnimTrack:Play()
		debounce = false
		wait(1)
		debounce = true
	end
end)
2 Likes