Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Global Variables Help?

Asked by 9 years ago

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

Log in to vote
2
Answered by 9 years ago

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
Thanks for the explained answer :D. drybones3363 30 — 9y
Ad
Log in to vote
-3
Answered by
dyler3 1510 Moderation Voter
9 years ago

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.

Answer this question