Problem with loading in animations

For some reason i keep getting an error which says this “LoadAnimation requires the Humanoid object to be a descendant of the game object” which is only thrown after i reset my character. Here is the code i am currently using

local Tool = script.Parent
local RS = game:GetService("ReplicatedStorage")
local Animations = RS.Animations
local player = game:GetService("Players").LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Humanoid:LoadAnimation(Animations.Curl)
local Debounce = false

i also tried adding this to wait for the character to be a descendant of game

while Character.Parent = nil do
  Character.AncestoryChanged:Wait()
end

It stopped the error from appearing BUT, the animations didn’t play anymore which makes no sense. I tried printing character’s parent after the loop, it prints workspace but still doesn’t play any of the animations. I also tried loading the animations when the player equips the tool but that also throws the error. At this point i’m begging to lean towards thinking this is a roblox bug.

1 Like

I didn’t get any errors, is this a local script located in startgui?

1 Like

This happens when i reset my character sorry i forgot to mention. This is a local script located inside of a tool.

1 Like

can I see the full script by chance? This will help me a lot more. Or you can just give me the context on how this is used. Like are you clicking then the animation plays?

1 Like

Sure thing, So i load the animation as seen above. I play the animation when the player clicks

Tool.Activated:Connect(function()
	if not Debounce then
		Debounce = true
		Animation:Play()
		Animation.Stopped:Wait()
		game.ReplicatedStorage.Remotes.ToolClick:InvokeServer()
		Debounce = false
	end
end)
1 Like

Interesting, try this script in a different game because my code is almost the exact same as yours and it’s working just fine. (I rewrote your code into studio)

1 Like

I have already made the game in TC and it is almost finished. Try storing the tool inside of replicated storage and cloning it to the player’s backpoack through a characteradded event on the server. Thats what i do and maybe that causes the problem. I have also been told by a friend that they had the same problem but, it went away after a day.

1 Like

Okay, I’m getting an error now. It’s nothing to do with cloning the tool to the player’s backpack. I’ll respond with a solution ASAP.

1 Like

Sure take your time buddy :+1:

1 Like

Okay, So I did some researching and I found this Post:

So, I applied a repeat until loop and to my surprise it worked.

this is what I have in my code:

local Tool = script.Parent
local RS = game:GetService("ReplicatedStorage")
local Animations = RS.Animations
local player = game:GetService("Players").LocalPlayer
-- Noticed how I removed the "local Character = player.Character or player.CharacterAdded:Wait()"
repeat wait() until player.Character
local Humanoid = player.Character:WaitForChild("Humanoid")
local Animation = Humanoid:LoadAnimation(Animations.Curl) 
local Debounce = false

Tbh, I have no clue why this worked.

here’s the place I worked in:
AnimationFix.rbxl (20.0 KB)

2 Likes

That is very interesting at actually does work 0.0. I also dk why it works. Thanks a lot, If you do happen to find the reasoning behind it please do let me know :open_mouth:

1 Like