Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation will not play when player is loaded, could someone help?

SO I just need someone to help me fix this bug in my game. When I put prints in the script nothing will print. I put the script in Server Script Service before, and now I put it in Starter Character, yet it still will not work. Here's the script.



game.Players.PlayerAdded:Connect(function(p)
	print(p.Name)
	p.CharacterAdded:Connect(function(c)
		print(c.Name)
		local a = script.Animation:Clone()
		a.AnimationId = script.Animation.AnimationId
		a.Parent = c
		local humanoid = c.Humanoid
		local dance = humanoid:LoadAnimation(a)
		dance.Looped = true
		dance:Play()
	end)
end)




3 comments

0

try putting it in workspace.

0

k thx

0

I got an error here it is: 06:52:09.298 - LoadAnimation requires the Humanoid object (Ruflixx.Humanoid) to be a descendant of the game object

1 answer

It’s because the Animation and everything exists before the Character loads. The character takes a bit of time to load but the player doesn’t. If you want to fix it then you need to wait till the character has changed it’s hierarchy:


game.Players.PlayerAdded:Connect(function(p)
    print(p.Name)
    p.CharacterAdded:Connect(function(c)
        print(c.Name)
        local a = script.Animation:Clone()
        a.AnimationId = script.Animation.AnimationId
        a.Parent = c
	
	while c.Parent == nil then 
		c.AncestryChanged:Wait()
	end

        local humanoid = c.Humanoid
        local dance = humanoid:LoadAnimation(a)
        dance.Looped = true
        dance:Play()
    end)
end)

I just found the solution by just searching your problem on google, sometimes you can find easier solutions, here’s the post that had the issue:

https://devforum.roblox.com/t/getting-error-loadanimation-requires-the-humanoid-object-to-be-a-descendant-of-the-game-object-despite-waiting-for-character/30784

This discussion is preserved as it was. New answers, comments, and votes are closed.