Animation doesn't want to play when player joins

I’m trying to make a LocalScript that makes the player play an animation when they join the game, The issue here is that Roblox’s output doesn’t want to tell me what’s wrong with my script, so I have no idea on how to fix the fact that the animation won’t play AT ALL when the player joins! I have tried so many Solutions, yet it refuses to work.

task.wait(1)
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		hum.WalkSpeed = 0
		local anim = script.Animation
			hum:LoadAnimation(anim)
		anim:Play()
end)
end)

Before you ask, the script is in StarterPlayerScripts. I’ve placed it in multiple other places and yet none of them refuse to work.

I would recommend two things:

  • I believe the method of playing animations directly from the Humanoid is deprecated. Use the Animator found inside the humanoid instead.
local anim = Humanoid.Animator:LoadAnimation(anim)
  • Try yielding until anim.Length > 0.
repeat task.wait() until anim.Length > 0
anim:Play()

You’d be surprised, it does not work, I’ve tried switching up the script multiple times and the animator Doesn’t work either.

What is the animation priority set to? The default idle animations may be overriding your animation.

It is not that, because the animation works perfectly fine on an NPC I made for the game and it doesn’t Override it. It’s the player-added thing but I have absolutely no idea how to fix it. It’s always the same junk with this player-added issue…

Try this in a LocalScript inside of StarterCharacterScripts to make sure the animation even works.

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")

local anim = hum.Animator:LoadAnimation(script.Animation)
anim:Play()
1 Like

If the localscript is in starterplayerscripts playeradded wont run because the script wont start until the player is already in the game

You’d be surprised as to how switching it to StarterCharacterScripts for the millionth time was the solution, thank you both a lot, but it’s strange how playeradded won’t run on PlayerScripts because
It worked when I switched up the walk speed strangely enough.

1 Like

I shouldnt say it wont run, cause it may run but it wont run consistently. It may work sometimes and other times it may not.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.