Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

With character loaded, why am I getting this error?

I am trying to insert an animation into my code for the first time. Here is my code:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local animaInstance = Instance.new("Animation")
animaInstance.AnimationId = "rbxassetid://4641537766"

local fireBallAnim = hum.LoadAnimation(animaInstance)
fireBallAnim:Play()

I am getting the error

The function LoadAnimation is not a member of Animation

I know the character has fully loaded, so I don't understand. Could I be getting this error if there is something wrong with the animation itself? What else am I missing out?

Thanks

1 answer

✓ Accepted answer

There's a mistake here with syntax. Instead of putting hum.LoadAnimation() You should say hum:LoadAnimation()

hum:LoadAnimatin() is a object function that loads in an animation you can play it at anytime. All roblox functions/methods use the colon instead of a dot.

Here is your script fixed with the error:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local animaInstance = Instance.new("Animation")
animaInstance.AnimationId = "rbxassetid://4641537766"

local fireBallAnim = hum:LoadAnimation(animaInstance)
fireBallAnim:Play()

This discussion is preserved as it was. New answers, comments, and votes are closed.