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

Does a local variable let every player in a server see the script?

I am confused with a variable in server scripting. The local variable and I keep thinking that the local variable doesn't let every player see the change in the server script. Can someone clarify for me?

local thing = script.Parent

thing = script.Parent

what is the difference

2 answers

It's the exact same. The only difference is scoping.

function print()
	local int = 10
	print(int) --Prints 10
end
print(int) --Will not print 10

In short, no local variables do not act like a local script. As long as the variable is inside of a server script, everyone will see what happens to the variable change, if you make it do something that people in the game can see.

A global variable has 1 value across the whole script. If you define it outside of a function or loop; just at the start of the script, you can only make changes one at a time.

X = 0 

For i = 1,5 do
     X =X + 1 
end
print(X)

This will end up printing 5, as that is how the script is read. It goes through the for loop, and sets X as 5 after it is all done.

A local variable has different values depending where you reference it in the script. You can change the value in a loop, but the original value on the outside does not change.


local X = 0 

For i = 1,5 do
   local X = 0
   X = X + 1
end
print(X)

Here, it will print 0, as the X inside the loop has no effect on the one outside of the loop. They are both their own variables, and for the most part don’t relate.

I hope this helped you understand!

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