sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
|
| 20 Jan 2016 09:50 PM |
I need a way to get server sided _G from a local script. Anyone know a way to do it? |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 09:54 PM |
RemoteFunction and a ServerScript
RF.OnServerInvoke = function(player,GVar)return _G[GVar]end |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 09:54 PM |
make a script in the workspace called global functions and inside it put
_G["Testing Function"] = function(text) print(text) end
make a script in the player and do local player = game.Players.LocalPlayer _G["Testing Function"]('Hi Guys my name is '..player.Name)
|
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 09:57 PM |
| Global and Local _G tables are two separate things. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 09:58 PM |
"I need a way to get server sided _G from a local script. Anyone know a way to do it?" he said :)
but your way works to0 :)
|
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 10:03 PM |
I read it three times. I see:
ServerScript _G.X=true
Player -Backpack --ServerScript player=game.Players.LocalPlayer --I don't think so! But even if it's a LocalScript... print(_G.X) --That won't be able to find the Server-sided _G. |
|
|
| Report Abuse |
|
|
sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
|
| 20 Jan 2016 10:06 PM |
@phoenix yeah, I'm using RemoteFunctions and they seem to work.
The other script wouldn't work because _G is different in server and local scripts. |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 10:10 PM |
Ok I thought I was missing something for a second lol Glad I could be of assistance. |
|
|
| Report Abuse |
|
|
sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
|
| 20 Jan 2016 10:13 PM |
| Wait nvm it doesnt seem to fire the OnServerInvoke function i binded to the remotefunction. |
|
|
| Report Abuse |
|
|
sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
|
| 20 Jan 2016 10:21 PM |
| Strange I got that function working now, but _G still seems to be local sided when I run the RemoteFunction |
|
|
| Report Abuse |
|
|
|
| 20 Jan 2016 10:29 PM |
I think it is pretty crappy that Roblox _G doesn't actually combine with the top level function environment in the script...
That's why...
setfenv(setmetatable({}, {__index = function(self, i) return getfenv()[i] or _G[i] end})) |
|
|
| Report Abuse |
|
|
sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
|
| 20 Jan 2016 10:51 PM |
How does that work? don't you need 2 arguments for setfenv? |
|
|
| Report Abuse |
|
|
sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
| |
|
|
| 21 Jan 2016 12:30 AM |
| Take a RemoteEvent and capture _G on server side and send it over remote event to client. That's the way it's done. |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2016 12:34 AM |
"RF.OnServerInvoke = function(player,GVar)return _G[GVar]end"
Talking about safe code.. |
|
|
| Report Abuse |
|
|