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: Global table not working

Previous Thread :: Next Thread 
Zorbon61 is not online. Zorbon61
Joined: 05 Jun 2012
Total Posts: 321
13 Feb 2015 03:14 PM
Players.Player1.Backpack.GuiScript:92: bad argument #1 to 'pairs' (table expected, got nil)

That's the error I get when I run this;

for h, k in pairs(_G.icon) do

however if I use a local table,

for h, k in pairs(icon) do

it doesn't error. Why is this an issue?
Report Abuse
RBXLuaDeveloper is not online. RBXLuaDeveloper
Joined: 11 Feb 2015
Total Posts: 47
13 Feb 2015 03:33 PM
Try

local table = _G.icon

for h, k in pairs(table) do
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
13 Feb 2015 03:38 PM
_G.icon is nil when you call the pairs function. Are you doing this in another script: _G.icon = {blah}?
Report Abuse
Zorbon61 is not online. Zorbon61
Joined: 05 Jun 2012
Total Posts: 321
13 Feb 2015 04:48 PM
Yeah, in my server script in the workspace; I have set _G.icon = {blah}. I tired local icon = _G.icon but that didn't work.
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
13 Feb 2015 04:57 PM
add this to top of ur script

repeat wait() until _G.icon ~= nil



I can't script better than you.
Report Abuse
Zorbon61 is not online. Zorbon61
Joined: 05 Jun 2012
Total Posts: 321
13 Feb 2015 05:01 PM
Doesn't work.
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
13 Feb 2015 05:11 PM
Then _G.icon is either never equal to anything but nil, or is being defined in a different scope.

Are you doing this with Server script to serverscript or localscript/serverscript to the opposite?

I can't script better than you.
Report Abuse
Zorbon61 is not online. Zorbon61
Joined: 05 Jun 2012
Total Posts: 321
13 Feb 2015 05:14 PM
The for loop is in a localscript in the player's backpack. The table is defined first in the serverscript in the workspace as;
_G.icon = {12345}
Report Abuse
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
13 Feb 2015 05:24 PM
before you do that, just put this:

while not _G.icon do end
Report Abuse
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
13 Feb 2015 05:25 PM
Just noticed your response; server-scripts and localscripts have different _G environments.

Try using ModuleScripts.
Report Abuse
Zorbon61 is not online. Zorbon61
Joined: 05 Jun 2012
Total Posts: 321
13 Feb 2015 05:30 PM
Oh, thanks!
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