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

Attempt to call a nil value even though value exists?

Asked by 2 years 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 4491 Moderation Voter Community Moderator
2 years ago
Edited 2 years 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 26 — 2y
0
nuuuuuuuuuuuuuuuu you got here first Puppynniko 1059 — 2y
Ad

Answer this question