Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

With character loaded, why am I getting this error?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
2
Answered by 4 years ago

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()
Ad

Answer this question