Ad
Log in to vote
0

Attempt to call a nil value even though value exists?

Asked by 13 days ago

I am replacing the default Animate script with a new one. I have new animations as well. The problem is that when I try to Load the animations, the LocalScript says attempt to call a nil value. This roughly what it looks like. Here is the script:

-- Loaded Animations
local Idle = LoadAnimation(script.IdleAnim)
local Running = LoadAnimation(script.RunningAnim)

-- Function to load animation
function LoadAnimation(animation)
    return Animator:LoadAnimation(animation)
end

Just so you know, Animator is defined.

Any Ideas?

1 answer

Log in to vote
0
Answered by
imKirda 4428 Moderation Voter Community Moderator
13 days ago
Edited 13 days ago
-- Function to load animation
function LoadAnimation(animation)
    return Animator:LoadAnimation(animation)
end

-- Loaded Animations
local Idle = LoadAnimation(script.IdleAnim)
local Running = LoadAnimation(script.RunningAnim)

As you probably know, scripts run from top to bottom, that means line 1, then line 2, then line 3, ...

If you create variable X at line 4, you can't print(X) at line 3 since at that time line 4 has not yet been run, same in your case, lines 2 and 3 where you create the variables were trying to run a function LoadAnimation that is going to be created on line 6.

0
Thanks :) iggyjelly1 6 — 13d
0
nuuuuuuuuuuuuuuuu you got here first Puppynniko 983 — 13d
Ad

Answer this question