Animation won't play

Hi, i’m trying to get an animation to play on a player as soon as they join, alongside some audio, i’d appreciate if someone could help me figure out how to make this work. I was trying to achieve the dance to start playing and the audio play with it too, but all that happens is an error comes up saying

[22:59:49.850 - LoadAnimation requires the Humanoid object (dameii.Humanoid) to be a descendant of the game object]
22:59:49.851 - Stack Begin
[22:59:49.854 - Script ‘Workspace.Script’, Line 13]


game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		local gu = humanoid.Parent:FindFirstChild("Animate")
		gu:Remove()
		local eyeyye = script.dance
		eyeyye.Parent = humanoid.Parent
		while true do
			local thesong = eyeyye.Audio
			thesong:Play()
			local animation1 = thesong.Parent.thedance
			animation1.Parent = humanoid.Parent
			local w = humanoid:LoadAnimation(animation1)
			w:Play()
			wait(35.865999999999999659)
			
		end
		
	end)
end)


Any help would be appreciated, thank you so much :D

I don’t think you need it’s parent to be Humanoid, consider deleting it and checking back?

1 Like

Animations should be handled by the client.

And if this is a localscript, the player is created before the localscript, hence: your PlayerAdded event will not run.

Animations should be handled on the client because the client has network ownership of their character. This error happens because the humanoid isn’t parented to the workspace yet. You should use the code below in a local script, and I added an if statement that checks if the character’s parent is nil, if so, the script will wait until it has its parent changed:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local eyeyye = script.dance
eyeyye.Parent = humanoid.Parent

local thesong = eyeyye.Audio
thesong:Play()

local animation1 = thesong.Parent.thedance
animation1.Parent = humanoid.Parent

if not (char.Parent) then
    char.AncestrChanged:Wait()
end

local w = humanoid:LoadAnimation(animation1)
w:Play()

thank you so much, I tried this script and tweaked it around as it was showing errors at first. Now it states

[23:30:38.810 - Players.dameii.PlayerScripts.dance:13: attempt to index nil with ‘Parent’]

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local animation1 = script.thedance
animation1.Parent = humanoid.Parent

local thesong = script.Audio
thesong.Parent = humanoid.Parent.Head
thesong:Play()


if not (char.Parent) then
    char.AncestrChanged:Wait()
end

local w = humanoid:LoadAnimation(animation1)
w:Play()

if you could help with this, that would be appreciated also, thanks again!

i tried that and it just came up with the same error, for me

oh okay, it wasn’t a LocalScript at the time, but i have changed it now.

I hadn’t realized that I used char instead of character and misspelt AncestryChanged, so change the portion of the script to this:

if not (character.Parent) then
    character.AncestryChanged:Wait()
end

thank you, i tried that and the animation didn’t work, turns out i had made the animation in R6, but was on R15!

it works now, thank you so much for your help, and everyone else! :smiley: