Why isn't my script working?

So I am making a custom animation script cause I don’t feel like importing the animate script from the character to the actual game. The error is line 5 and I am confused. Cause it shows no red lines in the script or any of that.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player:WaitForChild("Character")
local Anims = Character.Animate

--// Idle Animations
Anims.idle.Animation1.AnimationId = "rbxassetid://6671126042"
Anims.idle.Animation2.AnimationId = "rbxassetid://6671126042"

--// Walk/Sprint Animations
Anims.walk.WalkAnim.AnimationId = "rbxassetid://6673341968"
Anims.run.RunAnim.AnimationId = "rbxassetid://6691281060"
1 Like

What does the error on line 5 say?

I’d say it’d be easier to insert the actual Animate script and modify it from there. But I am so confused why it is giving an error. Line 5 seems to be a comment?

It says “Can’t find Animate in the character” But I fixed it by adding :FindFirstChild

But I am now getting errors on line 6

00:21:58.443 Workspace.anxlr.Scripts.CharacterScripts.Animate:6: attempt to index nil with ‘WaitForChild’ - Client - Animate:6

What code is that? Also it’s exactly what it says on the error. You are trying call a function on a nil value.

You realize half of the errors in script say that even tho the script it in the correct spot and coded the correct way

If there are errors, then it isn’t written correctly. Answer the question, otherwise I can’t help you.

alr so its a local script in 2 folders in characterscrippts

1 Like

try this:

--locals
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() -- < < < it not Player:WaitForChild("Character")
local Anims = Character:WaitForChild("Animate")

--Idle animation
Anims.idle.Animation1.AnimationId = "rbxassetid://6671126042"
Anims.idle.Animation2.AnimationId = "rbxassetid://6671126042"

--Walk and Run animation
Anims.walk.WalkAnim.AnimationId = "rbxassetid://6673341968"
Anims.run.RunAnim.AnimationId = "rbxassetid://6691281060"
1 Like

If you make Player:WaitForChild("Character"),it only try to find an object.

Player:WaitForChild("Character")

This will give you an infinite yield because Character is a property of Player, not a child