|
| 30 Nov 2016 05:56 PM |
I'm having trouble remember how to get an object by using a table value, for instance:
local tab = {part} local Part = game.Workspace.tab[1]
is what I'm trying to accomplish, but I don't know or can't remember how it's done. Any help is appreciated! |
|
|
| Report Abuse |
|
|
Wrathsong
|
  |
| Joined: 05 Jul 2012 |
| Total Posts: 22393 |
|
|
| 30 Nov 2016 05:59 PM |
part is undefined but
local tab = {part} local Part = workspace[tab[1]]
Ever wanted to learn how to script? Check out my YouTube channel: youtube.com/austintheslayer Want to see me code in action? Follow my twitch: twitch.tv/austinrblx |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2016 06:03 PM |
That's what I was originally doing, but it kept erroring out, saying it expected a string but got an object
local plrs = {}
game.Players.PlayerAdded:connect(function(plr) table.insert(plrs,plr) end)
function roundStart()
for i=1,#plrs do print(plrs[i]) print(game.Players[plrs[i]]) end end
Why does it do this? |
|
|
| Report Abuse |
|
|
Wrathsong
|
  |
| Joined: 05 Jul 2012 |
| Total Posts: 22393 |
|
|
| 30 Nov 2016 06:07 PM |
game.Players.PlayerAdded:connect(function(plr) plrs = game.Players:GetPlayers() end)
Ever wanted to learn how to script? Check out my YouTube channel: youtube.com/austintheslayer Want to see me code in action? Follow my twitch: twitch.tv/austinrblx |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2016 06:08 PM |
| I still get the same error with that method :( |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 30 Nov 2016 06:18 PM |
function roundStart()
for _,v in pairs(game.Players:GetPlayers())do print(v:GetFullName()) --v is the player end for i=1,#plrs do print(plrs[i]) print(game.Players[plrs[i]]) end end
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 30 Nov 2016 06:18 PM |
Whoops get rid of the second for loop. I was using that for reference to your script
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2016 06:21 PM |
if tab is an array of instances, rather than names, you use local Part = tab[1]
if tab is an array of string names, use
local Part = workspacce[tab[1]] |
|
|
| Report Abuse |
|
|
|
| 02 Dec 2016 08:30 AM |
I've figured out the issue to my problem. When I added players to the players table, it was referencing the game.Players.Player1 object, not the player string. I've fixed this by changing the for loop to this:
for i=1,#plrs do local pString = tostring(plrs[i]) print(plrs[i]) print(game.Players[pString]) end
Now everything works just as expected. If you can think of a better way to do this, I'd love to know! Thanks to everyone who helped my thought process :P |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 02 Dec 2016 10:03 AM |
@OP
GetPlayers already returns a table.
local players = game.Players:GetPlayers()
for i,v in next, players do print(v.Name) end
|
|
|
| Report Abuse |
|
|