Why is :WaitForChild not working?

I am trying to put an animation into my game that is triggered by using a tool. I try to declare the variables but when I put :WaitForChild it gives me this error:

Code where the error is happening

local Mouse = game.Players.LocalPlayer:GetMouse()
local Character = game.Players.LocalPlayer.Character
local Humanoid = Character:WaitForChild(“Humanoid”)
local Animator = Humanoid:WaitForChild(“Animator”)
local AnimationClip = script.Animation
local LoadedAnimation = Animator:LoadAnimation(AnimationClip)

I don’t get why it is doing this. Could someone please explain?

The Character may have already loaded ahead of time before the script even started to detect it, you could just change your Character variable to

local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

It means that Character is not a valid variable, often when calling Player.Character the Character hasn’t loaded yet which sets the variable to nil

You can wait for Character to load with the following code:

repeat wait() until Player.Character

Although this method is highly recommended.