LoadAnimation error after player died

Hello iam getting an error but the error only appears when I die , by that I mean that everything is fine until I die and I cant use the Tool.

Error : LoadAnimation requires the Humanoid object (MyUsername.Humanoid) to be a descendant of the game object

The Error line is at the local Idle and local SitUp

local Tool = script.Parent
local Debounce = true
local Player = game:GetService("Players").LocalPlayer
local RepStorage = game:GetService("ReplicatedStorage")
local Track1 = RepStorage.Animations.SitUpIdle
local Track2 = RepStorage.Animations.SitUp
local Character = Player.Character or Player.CharacterAdded:Wait()
local EquipRemote = RepStorage.Events.EquipRemote
local Humanoid = Character:WaitForChild("Humanoid")
local NoStam = false

local Idle = Character:WaitForChild("Humanoid"):LoadAnimation(Track1)
local SitUp = Character:WaitForChild("Humanoid"):LoadAnimation(Track2)

Tool.Activated:Connect(function()
	if Player.StatFolder.Doing.Value == "Running" or Player.StatFolder.Doing.Value == "Meditation" or Player.StatFolder.Doing.Value == "PushUp" then return end
	if Debounce == false then return end
	Debounce = false
	
	SitUp:Play()
	if Player.StatFolder.Defense.Value < 850 then
		RepStorage.Events.SitUp:FireServer("Began")
		SitUp:AdjustSpeed((Player.StatFolder.Defense.Value + 0.2) / 1000)
		SitUp.Stopped:wait()
		if NoStam == true then return end
		RepStorage.Events.SitUp:FireServer("Ended","YAY")
	else
		RepStorage.Events.SitUp:FireServer("Began")
		SitUp:AdjustSpeed(1.8)
		SitUp.Stopped:wait()
		if NoStam == true then return end
		RepStorage.Events.SitUp:FireServer("Ended","YAY")
	end 
	
	wait(0.3)
	
	Debounce = true
end)

Tool.Equipped:Connect(function()
	if Player.StatFolder.Doing.Value == "Running" then return end
	EquipRemote:FireServer("Equipped","SitUp")
	Idle:Play()
	Humanoid.WalkSpeed = 0
	Humanoid.JumpPower = 0
	wait(0.8)
	Idle:AdjustSpeed(0)
end)

Tool.Unequipped:Connect(function()
	if Player.StatFolder.Doing.Value == "Running" then return end
	EquipRemote:FireServer("UnEquipped","SitUp")
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
end)

Thats almost the full script

1 Like

After the line where you create the humanoid variable, write

if not Character.Parent then
    Character.AncestryChanged:Wait()
end
2 Likes

Thnx it did worked
and there is another solution I just discovered wich is
instead of

local Character = Player.Character or Player.CharacterAdded:Wait()

i did

local Character = Player.CharacterAdded:Wait() or Player.Character

:smiley: Thnx for ur reply

1 Like