Question about the variables

I want to know why sometimes, the variables that don’t have the ‘local’ in front of it aren’t marked as error or underlined but other times, it does. Here is what I meant:
Not marked as error
image
Marked as error
image

When you hover over the variable, what does it say?

In Lua (and Luau, but not supported with analysis), variables are always global unless you tag them with local.

local function f()
	a = 1
end

print(a) -- 1

In normal Lua, all globals are put inside the environment table (getfenv()), which is by default _G.

Roblox changed the behavior of _G so that it was just a blank shared table across scripts, and its use and global variables are now obsolete.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.