Animation doesn't play when attempting to play right when character spawns

I have a local script placed in starterpack, and once it gets the character and humanoid, it plays the animation by loading it in with the animator. The problem is that I play the animation as soon as the script starts, with no errors, and it doesn’t play. When I play it after around a second, it works. I don’t want to wait a second to play it because it looks ugly, is there a reason why this happens? Any help appreciated

Have you used waitforchild()? It could be that the animationID did not load once you have ran the game, or your character did not load, then loaded afterwards so that you can play it. Showing your script will also be helpful.

1 Like

You can try using the CharacterAppearanceLoaded function and adding a wait function after it such as .CharacterAppearanceLoaded:Wait() and then play the animation. I am guessing that the character didn’t load correctly and you played the animation during that time? as @cheesy_roblox190 said, showing your script will also be helpful.

1 Like

Here is my code

Paste it in a code block, instead of a screenshot. We can’t do anything with a screenshot :confused:

Sorry about that

local Player = game.Players.LocalPlayer
local Character
repeat task.wait()
	Character = Player.Character
until Character ~= nil



local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local AnimationsFolder = script.Parent.Animations

local CD = 1
local Active = false

local UserInputService = game:GetService("UserInputService")

local ServerHandler = script:WaitForChild("ServerHandler")

local Debris = game:GetService("Debris")

local HitboxModule = require(game.ReplicatedStorage.MainAssetBase.Modules.HitboxModule)

if Humanoid and HumanoidRootPart then
	--task.wait(.75)
	local Animator = Humanoid:FindFirstChildWhichIsA("Animator")
	
	Player.CharacterAppearanceLoaded:Wait()
	
	local IdleAnimation = Animator:LoadAnimation(AnimationsFolder:WaitForChild("IdleAnimation"))
	local AttackAnimation1 = Animator:LoadAnimation(AnimationsFolder:WaitForChild("AttackAnimation1"))
	IdleAnimation.Priority = Enum.AnimationPriority.Action
	IdleAnimation:Play()
end

I tried this, it did not seem to work

When I use CharacterAppearanceLoaded:Wait(), it yields forever and doesn’t continue. Maybe because I have a custom character? Not sure

1 Like

Use player.CharacterAdded:Wait()

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
if Character then
    print("Character!")
end