I will put _G.GamesPlayed = 0 in a Server Script. I will then go to the command line in studio and say:
print(_G.GamesPlayed)
and it prints nil any reason why?
The server scripts, local scripts and command line all use a different global environment. This means that the _G
table will be different for each of them.
If you want to see _G.GamesPlayed
, you'll have to use a separate server script to print it out.
Example
Server script, inside Workspace or ServerScriptService
game.Workspace:WaitForChild("PRINT_GAMESPLAYED") print(_G.GamesPlayed)
In command line, put this whenever you want
Instance.new("Part", workspace).Name = "PRINT_GAMESPLAYED"
A more complex way to do it is to use remote/bindable events/functions.
Scripts don't fire until the game starts up. So the value doesn't exist until you start the game. Try to go into a game and use the command line then.