Problem Loading Animations After Death

Hi Everyone,
I’m having an issue where I can’t load animations after the player dies. When I try, I get this error message:
image
And, if I could, I’d do what the other forum posts said, which is to load the animations inside a tool.Equipped function or use character.AncestryChanged, but the problem is that I’d be using the animations from outside the function, and I wouldn’t have access to them. I’ve looked at multiple forums but nothing seems to solve my problem exactly. All help is appreciated, thank you :happy1:

-->> Servies
local UIS = game:GetService("UserInputService")  print("UIS loaded...")

-->> PlayerInfo
local player = game.Players.LocalPlayer  print("Player loaded...")
local character = player.Character or player.CharacterAdded:wait()  print("Character loaded...")

repeat wait() until character.AncestryChanged

local hum = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local defaultAnim = character:WaitForChild("Animate")

-->> Misc
local tool = script.Parent
local debounce = false
local mouse = player:GetMouse()

-->> Animations
local swordAnim = Instance.new("Animation")
swordAnim.AnimationId = "rbxassetid://7063201015​"
local swordAnimTrack = character.Humanoid:LoadAnimation(swordAnim)

local rapidSwordAnim = Instance.new("Animation")
rapidSwordAnim.AnimationId = "rbxassetid://7069526371​"
local rapidAnimTrack = character.Humanoid:LoadAnimation(rapidSwordAnim)

local swordFinal = Instance.new("Animation")
swordFinal.AnimationId = "rbxassetid://7118859846​"
local finalTrack = character.Humanoid:LoadAnimation(swordFinal)

-- Below is key detection using the UIS, and that's where the animations are used

i think you should remove this, its the preset format for posts

1 Like

Thank you, I must’ve missed it

EDIT: I think I fixed your problem. The ancestry of a player doesn’t change so character.AncestryChanged would probably do nothing. I would suggest using hum.Died to reload everything. Here is the script. I tested it out on a tool in StarterPack and no errors came up. I reset and all 3 things were printed.

-->> Services
local UIS = game:GetService("UserInputService")  print("UIS loaded...")

-->> PlayerInfo
local player = game.Players.LocalPlayer  print("Player loaded...")
local character = player.Character or player.CharacterAdded:wait()  print("Character loaded...")
local hum = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local defaultAnim = character:WaitForChild("Animate")


hum.Died:Wait()

-->> Misc
local tool = script.Parent
local debounce = false
local mouse = player:GetMouse()

-->> Animations
local swordAnim = Instance.new("Animation")
swordAnim.AnimationId = "rbxassetid://7063201015​"
local swordAnimTrack = character.Humanoid:LoadAnimation(swordAnim)

local rapidSwordAnim = Instance.new("Animation")
rapidSwordAnim.AnimationId = "rbxassetid://7069526371​"
local rapidAnimTrack = character.Humanoid:LoadAnimation(rapidSwordAnim)

local swordFinal = Instance.new("Animation")
swordFinal.AnimationId = "rbxassetid://7118859846​"
local finalTrack = character.Humanoid:LoadAnimation(swordFinal)
1 Like

Are you sure the animations loaded? I can’t test it unfortunately since I’m in bed but I’d think that nothing below ‘hum.Died’ would fire until the humanoid dies

Ok, I’ll make some basic animations and test it out more.

Well, I’ve gotta get to bed. Theres 2 things that might be stopping it. 1: A new humanoid is created so it sets the hum variable to nil. 2: The error refers to descendants which could mean that the tool and player fail the second or more times. The script:

-->> Services
local UIS = game:GetService("UserInputService")  print("UIS loaded...")

-->> PlayerInfo
local player = game.Players.LocalPlayer  print("Player loaded...") 
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("Humanoid")
local hum = character.Humanoid
local rootPart = character:WaitForChild("HumanoidRootPart")
local defaultAnim = character:WaitForChild("Animate")

local swordAnim = Instance.new("Animation")
swordAnim.AnimationId = "rbxassetid://7134749068​"
local swordAnimTrack = hum:LoadAnimation(swordAnim)

local rapidSwordAnim = Instance.new("Animation")
rapidSwordAnim.AnimationId = "rbxassetid://7134753398​"
local rapidAnimTrack = hum:LoadAnimation(rapidSwordAnim)

local swordFinal = Instance.new("Animation")
swordFinal.AnimationId = "rbxassetid://7134757681​"
local finalTrack = hum:LoadAnimation(swordFinal)
-->> Misc
local tool = script.Parent
local debounce = false
local mouse = player:GetMouse()

tool.Activated:Connect(function()
	local randomNum = math.random(1, 3)
	print(randomNum)
	if randomNum == 1 then
		swordAnimTrack:Play()
		print("Done")
	end
	if randomNum == 2 then
		rapidAnimTrack:Play()
		print("Done")
	end
	if randomNum == 3 then
		finalTrack:Play()
		print("Done")
	end
end)

hum.Died:Connect(function()
	print("No player found!")
	player.CharacterAdded:Wait()
	character = player.Character
end)
1 Like

Hmm, ok. Thanks for the effort, I’ll be sure to try to figure it out tomorrow!

You need to redefine the humanoid every time the player dies because it doesn’t exist anymore

So, how is that different from this?
local hum = character:WaitForChild("Humanoid")
Since that runs before the animations load I’d figure that it achieves what you said