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

Attempt to call a nil value even though value exists?

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

✓ Accepted answer
-- 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.

2 comments

0

Thanks :)

0

nuuuuuuuuuuuuuuuu you got here first

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