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 |
|
|
|
| 13 Feb 2015 03:33 PM |
Try
local table = _G.icon
for h, k in pairs(table) do |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 05 Jun 2012 |
| Total Posts: 321 |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 13 Feb 2015 05:24 PM |
before you do that, just put this:
while not _G.icon do end |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2015 05:25 PM |
Just noticed your response; server-scripts and localscripts have different _G environments.
Try using ModuleScripts. |
|
|
| Report Abuse |
|
|
Zorbon61
|
  |
| Joined: 05 Jun 2012 |
| Total Posts: 321 |
|
| |
|