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

The difference between local and regular?

I don't get local stuff. I know the local statement when using local variables.

j = 10         -- global variable
    local i = 1    -- local variable

I'm pretty sure I need to get filled in on a lot of other 'local' stuff. Can anyone explain to me? Thanks.

1 answer

✓ Accepted answer

local variables are in a scope, when they're put at the top of a script they can be used for everything in the script because everything is in their scope. However, if you put a local variable inside of a function, you can only use it inside of that function, if you don't make it local, it can be accessed outside of the function, because it's global. You can also set a variable later by making it local.

local var
var = "hello"
function pr()
	local var = "Hello"
end

print(var) ->nil
function pr()
	var = "Hello"
end

print(var) ->Hello

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