Animation Not Playing

Hello Roblox developer community! I am attempting to play an animation, but it isn’t working. I am a beginner scripter, do you guys know what’s wrong with my code? Please note that I am only posting part of my code, because there is no point in posting the parts that work.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local anim = script.Parent.Fall
local animLoad = animator:LoadAnimation(anim)
animLoad:Play()

Does the code error? If not, then it could be

local character = player.Character if the character doesn’t exist by the time the script runs, it will nil, so change the line to local character = player.Character or player.CharacterAdded:Wait()

Is the script running? What type of script is it and where is located? If it’s a localscript, ensure it is located in a place that they can run in, PlayerGui, StarterPlayerScripts, StarterCharacterScripts, anything that is a descendant/related to a player instance

1 Like

Surprisingly, no.

Didn’t work.

It is running, it’s a ServerScript inside of a tool.

I know that won’t work before even trying it because you are creating a variable after using it.

Thats weird, for me it does. Just make sure your script.Parent.Fall exists. Otherwise i don’t know dude…

Try Humanoid:LoadAnimation(), I use it all the time.

Oh, I thought it wouldn’t work because you created a variable after you used the variable in that script. I was just looking the script over and I noticed that so I thought it wouldn’t work. I understand my error now. Sorry, I’m a beginner scripter, so I didn’t notice you called the function creating the variable before you called the function using it as a parameter.

I think because you use Players.LocalPlayer in server script. But, if this right. There should be an error " attempt to index nil with Character"

Then if that is the case check if you put the correct animation ID.

All good,

You see, this made me mad:

and

Take this tip from an experienced programmer:

  • Trail and error is KEY
  • Its oke to make mistakes, its oke for the compiler to throw errors
  • learn from your mistakes, read the errors
  • It wont harm to google: ‘How to create a part in roblox with script’, ‘How to set size of part roblox’
  • Documentation is your boss aka. Read through the documentation, if you scrooll down you get a full example.

In general those tips work when programming (not only roblox).

Just next time, don’t ask for help if you are not willing to try solutions people provides you. It takes time to make those solutions and if you just say. YES THAT WONT WORK CAUSE I’M BETTER THEN A COMPILER you are just ego trippin. Try to run it atleast once and ask questions on things that happen when trying the provided solution.

Anyway, have a nice day

Alright, sorry for not taking advice from someone who is most likely a way better programmer than me. Have a nice day.

Again, its not about taking advice, its about not running code and assuming what the result is going to be without understanding the code…

Alright, thank you for your help. I will attempt to do better next time.

All good,

I believe @rfisty has an answer on your question and posted it into this post

Alright, I will. Like I said, have a nice day and thank you for your help.