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
 

Re: Anyone know a way to get server _G from localscript?

Previous Thread :: Next Thread 
sayhisam1 is not online. 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
phoenix53124 is not online. phoenix53124
Joined: 25 Feb 2009
Total Posts: 4889
20 Jan 2016 09:54 PM
RemoteFunction and a ServerScript

RF.OnServerInvoke = function(player,GVar)return _G[GVar]end
Report Abuse
FearlessBiscuit is not online. FearlessBiscuit
Joined: 16 Jun 2013
Total Posts: 1157
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
phoenix53124 is not online. phoenix53124
Joined: 25 Feb 2009
Total Posts: 4889
20 Jan 2016 09:57 PM
Global and Local _G tables are two separate things.
Report Abuse
FearlessBiscuit is not online. FearlessBiscuit
Joined: 16 Jun 2013
Total Posts: 1157
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
phoenix53124 is not online. phoenix53124
Joined: 25 Feb 2009
Total Posts: 4889
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 is not online. 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
phoenix53124 is not online. phoenix53124
Joined: 25 Feb 2009
Total Posts: 4889
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 is not online. 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 is not online. 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
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
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 is not online. 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 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
20 Jan 2016 11:30 PM
bump
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
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
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
21 Jan 2016 12:34 AM
"RF.OnServerInvoke = function(player,GVar)return _G[GVar]end"

Talking about safe code..
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