Help with: Global Variables

I’m trying to make a global variable that contains some strings.
In lua/autorun/server/myFile.lua (When the server starts)
[lua]
myStringsG = {“Hello”, “HelloAgain”, “AndHello”}
[/lua]
Another script (not the same file) that use the variable (client side):
[lua]
if not myStringsG==nil then
for i=1,table.Count(myStringsG) do
if(ply:Nick()==myStringsG*) then
MsgN(“Nope, youre not him”)
end
end
else
MsgN(“Variable doesn’t exists”)
end
[/lua]
It’s a very simplified version of my code but I think that’s enough to demonstrate my problem.
Errors?
While I would say I should be able to do it that way, I get my error output “Variable doesn’t exists”.
What am I doing wrong with the variable…?

This is because your variable isn’t networked or shared.

Server code is executed on the computer running the game server and client code is executed on every player’s machine. They have no way to know the contents of myStringsG if it was only defined on the server.

The simplest way to do this is to also define MyStrinsG clientside. You could also broadcast it to the clients if it’s likely to change often.

If security is what you have in mind do not trust the client. Have the server do all the security checks.

Thank you very much for you help.
The variable is only to be changed on server initialise, but the clients should be able to get its content at all time.
Isn’t the script only able to get content from Net.Broadcast when it’s sending? And since it’s a function that’s called by the user to get the variable it wont be very efficient to send it every x second.

Is it even possible to make a constant global variable that contains a table with some strings?

Any variable that isn’t local is global, or do you mean a table present on both the server and the client?

If it’s the second case just create a file named shared.lua and include it on both the client and the server. Put things in there that you want both lua states to have access to.

Well, that would only solve a part of my problem. I could do what you said with the two scripts I posted, but what if I use the variable in one of the client gamemode files as well? Do I have to define it there as well or can I do it in another tricky way :)?

Any variable that doesn’t have “local” in front of it can be accessed anywhere else in the same lua state (client or server). This is why using local on everything you don’t want to be accessible from outside that file is very important.

Thus you can declare your table in any clientside file and use it in any other one.

[lua]Globaltable = {“A”,“B”,“C”}[/lua]