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

My animation will not play when the character loads. Could someone help me?

Ok, so I was working on a script that will make an animation play when I player's character is loaded. I have placed the script in three places, Server Script Service, StaterPlayer, and in the workspace. However, when I placed the script into workspace it printed what I needed it to print, but it did not work, here's the error: 12:16:41.452 - LoadAnimation requires the Humanoid object (Ruflixx.Humanoid) to be a descendant of the game object

And, 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)




keep in mind the script is currently in the workspace, thx <3

1 answer

✓ Accepted answer

I added something to make sure the character's parent is the workspace.

Also, it's not really required to clone the script. Since you just load the ID into the humanoid, it can be used without cloning.

Try it with the following script and let me know what it does ^w^

game.Players.PlayerAdded:Connect(function(p)
	print(p.Name)
	p.CharacterAdded:Connect(function(c)
		while c.Parent == nil do --Wait until the character's parent is the workspace
			c.AncestryChanged:wait()
		end
		print(c.Name)
		local a = script.Animation
		local humanoid = c:WaitForChild("Humanoid")
		local dance = humanoid:LoadAnimation(a)
		dance.Looped = true
		dance:Play()
	end)
end)

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