generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Global variable access

Previous Thread :: Next Thread 
Parkderp1 is not online. Parkderp1
Joined: 19 Jan 2014
Total Posts: 139
23 Apr 2015 10:27 PM
Are global variables that are made in a server script accessible by local scripts (client scripts)?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Apr 2015 10:30 PM
Nope
Report Abuse
Parkderp1 is not online. Parkderp1
Joined: 19 Jan 2014
Total Posts: 139
23 Apr 2015 10:37 PM
Tehn is there a way to make a variable that's accessible by all scripts.?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Apr 2015 10:39 PM
Nope, you gotta use RemoteFunction/RemoteEvents for this.
If they are static (as in you don't plan on changing them) then you can use a ModuleScript.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
23 Apr 2015 10:42 PM
Instead of remote events just make a value inside of workspace and use that as a variable. @cantkillme i swore you can use global variables in server and client scripts
Report Abuse
Parkderp1 is not online. Parkderp1
Joined: 19 Jan 2014
Total Posts: 139
23 Apr 2015 10:43 PM
How would I make a global variable in client scripts, they only work in a Player and that stuff.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
23 Apr 2015 10:44 PM
@Park, yes. Global variables are accesible by both Server Scripts and local scripts.

Server script

_G.x = 5

local script

print(_G.x)
Report Abuse
Parkderp1 is not online. Parkderp1
Joined: 19 Jan 2014
Total Posts: 139
23 Apr 2015 10:47 PM
^ Tested, didn't work and I just found this after a lot of researching:

Keep in mind that the server has a different _G than clients do, so you can't define a global function in a server script and then use it from a LocalScript.

Roblox Wiki
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
23 Apr 2015 10:49 PM
Server script
_G.x = 5


Local Script:
while wait() do
print(_G.x)
end

I just tested this. It works.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
23 Apr 2015 10:50 PM
local script is inside the startergui
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Apr 2015 10:50 PM
Time, you should look up on how memory works.
It probably works for you because you are testing on play solo, where the client IS the server.
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
23 Apr 2015 10:52 PM
It won't work
JUst use a "Value" object and both server and clients can see and modify it(if FE off)
Report Abuse
Parkderp1 is not online. Parkderp1
Joined: 19 Jan 2014
Total Posts: 139
24 Apr 2015 06:35 AM
Here's my variable:
_G.PlayerARESReason={}


_G.PlayerARESReason[player.Name]={}
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
24 Apr 2015 06:38 AM
You can't transfer data from client to server and server to client with _G or shared. Use RemoteEvents or RemoteFunctions.
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
24 Apr 2015 06:41 AM
"JUst use a "Value" object and both server and clients can see and modify it(if FE off)"
That's a bad idea. It's ugly and messy, and it doesn't really have an advantage. RemoteFunctions and RemoteEvents give you practice working with them, more understanding of the client-server model, and are much cleaner and more preferred.
Report Abuse
Parkderp1 is not online. Parkderp1
Joined: 19 Jan 2014
Total Posts: 139
24 Apr 2015 03:32 PM
Thanks Alot! :) ^
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
25 Apr 2015 01:12 PM
@Vis

Using to many RemoteEvents/RemoteFunctions will lead to lag. Why use them when there is a quicker and less laggy way to do it.
Report Abuse
Tevolo is not online. Tevolo
Joined: 13 Nov 2009
Total Posts: 1252
25 Apr 2015 01:25 PM
Just use ModuleScripts.
Report Abuse
Parkderp1 is not online. Parkderp1
Joined: 19 Jan 2014
Total Posts: 139
26 Apr 2015 10:04 AM
You can't update a a module script.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
26 Apr 2015 10:12 AM
"Using to many RemoteEvents/RemoteFunctions will lead to lag. Why use them when there is a quicker and less laggy way to do it."
I don't think you understand. When you transfer data from client to server and vise-versa, there will ALWAYS be lag - it isn't just the RemoteEvents and RemoteFunctions that do it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image