Are they running on the client even if its on servers script? or could they be called “Private”
the local keyword means that they are local to that scope of code. They cannot be accessed by any greater scope level.
If you make it global, by not including the local keyword, it will be accessible anywhere in the script.
This also applies to functions.
foo() --> attempt to call a nil value
bar() --> "called 2"
local function foo()
print("called")
end
function bar()
print("called 2")
end
foo() --> "called"
print(param) --> nil
local function foo(param: number): any?
local bar = 3
if param ~= 10 then
param += bar --works, because bar is created at a greater scope than the current one
local addFactor = 10
end
param += addFactor --> Attempt to perform arithmetic (add) on number and nil
--addFactor is created at a lower scope level than this one.
--if we removed the 'local' keywork when making 'addFactor', this would work, provided param is not 10.
end
I think you got confused with a LocalScript. All local generally means is that it’s running, well, locally, in an “enclosed” space as sort.
A LocalScript will run on the client. It runs locally on the player’s machine.
Why do developers type “Local” at the top of their scripts?
because using local more will optimize your code. once you get a lot of variables it is crucial to use local since the engine will only check that scope rather than every individual scope.
As @Waddazy said.
Imagine you have 20 functions in a script but you only need the variable onlyThisOne in just one of them.
If you make it local onlyThisOne inside that function it doesn’t search outside that function for any other use of it.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.