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

Global Variables Help?

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?

2 answers

✓ Accepted answer

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.

1 comment

1

Thanks for the explained answer :D.

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.

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