Sometimes Studio can't separate global from local variables

I’ve encountered this quite a few times and while it’s not exactly a problem for game production, it is getting a bit confusing when debugging old scripts and trying to work away “warnings”;


As you can see; “sittingIdle” is called on line 42 and again on line 53; so it is obviously not a local variable, right?

It appears to only be used inside the function called when InputBegan is fired, so it does appear to be local.
The problem is you want to use it as a global variable which means you should really initialise it outside of that scope.

1 Like

You can fix it by writing somewhere in the global scope: (before InputBegan connection)

sittingIdle = nil

Or

local sittingIdle

This is nice for yourself as well, then you know that there is a variable named “sittingIdle” which is set and used in the global scope. Good coding practice!

1 Like

@pauljkl @buildthomas thanks :slight_smile: