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: What would this print?

Previous Thread :: Next Thread 
Dollar500 is not online. Dollar500
Joined: 12 Jan 2013
Total Posts: 504
30 Apr 2016 10:54 PM
local players = game.Players:GetPlayers()

local myTable = {}

for i, v in pairs(players) do
myTable[v] = i
print(myTable[v])
end

-- I am not at a computer and I'm trying to write a script. Would this just print 1, 2, 3, etc.?
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
30 Apr 2016 10:59 PM
Wotdafok r u even trying to do

tab={}

for i,v in pairs(game.Players:GetChildren()) do
table.insert(tab,v)
end

for i,c in pairs(tab)
print(i,c)
end

Output:

1 Player1
2 Player2
3 Player3
4 Player4
5 Player5

etc (stops at the end of the table of players)
Report Abuse
Dollar500 is not online. Dollar500
Joined: 12 Jan 2013
Total Posts: 504
30 Apr 2016 11:02 PM
LuLuLukas, that is not what I am trying to do. I am trying to assign a number to each player.
Report Abuse
Dollar500 is not online. Dollar500
Joined: 12 Jan 2013
Total Posts: 504
30 Apr 2016 11:04 PM
I want it to print this:

Player1 -> 1
Player 2 -> 2
Player3 -> 3

etc
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
30 Apr 2016 11:05 PM
That's what the index numbers are for in a table

tab={player1,player2,player3}

tab[1] --same as player1
tab[2] --same as player2
tab[3] --same as player3

Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
30 Apr 2016 11:13 PM
If you want it to print it that exact way, just change print(i,c) to print(c,"->",i)
wow
Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
30 Apr 2016 11:19 PM
Now if you're trying to make something like

print(players[Dollar500]) -> "1"

then you want to start with an empty table and for each player in the game, assign the number to their reference name in the table

Players = {}
for i, v in pairs(game.Players:GetPlayers()) do
Players[v.Name] = i
end
print(Players[Dollar500])

you can also reference the players directly [if i recall correctly] instead of using their name in the table. i may be completely wrong on that.

Players = {}
for i, v in pairs(game.Players:GetPlayers()) do
Players[v] = i
end
print(game.Players.Dollar500) -> "1"
Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
30 Apr 2016 11:20 PM
i also totally butchered that last line of the post

*print(Players[game.Players.Dollar500]) -> "1"
Report Abuse
Dollar500 is not online. Dollar500
Joined: 12 Jan 2013
Total Posts: 504
30 Apr 2016 11:22 PM
Well, I think I am actually trying to do this:

local tab = {a = 1, b = 2}

I am trying to do this by inserting the values with a for loop.
Report Abuse
Dollar500 is not online. Dollar500
Joined: 12 Jan 2013
Total Posts: 504
30 Apr 2016 11:26 PM
If I did this:

Players = {}
for i, v in pairs(game.Players:GetPlayers()) do
Players[v.Name] = 10
end
print(Players[Dollar500])

Would it print 10?
Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
30 Apr 2016 11:27 PM
should.
Report Abuse
Dollar500 is not online. Dollar500
Joined: 12 Jan 2013
Total Posts: 504
30 Apr 2016 11:27 PM
Ok. 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