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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 23 Apr 2015 10:50 PM |
| local script is inside the startergui |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 19 Jan 2014 |
| Total Posts: 139 |
|
| |
|
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
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 1252 |
|
| |
|
Parkderp1
|
  |
| Joined: 19 Jan 2014 |
| Total Posts: 139 |
|
|
| 26 Apr 2015 10:04 AM |
| You can't update a a module script. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|