Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 10 Jan 2013 02:18 PM |
So i got this script of a naked guy with blue colors, anyway he posted this script:
function randomplr() local players = game.Players:GetPlayers() return players[math.random(1, #players)] end
print(randomplr())
So, the return, did it return ALL the players, and another question, the # sign before players, does that make it so it will print a number? |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 10 Jan 2013 02:21 PM |
What that does is return a random player.
I'll describe it: define function randomplr set local variable players to a table of all players in game return math.random of 1 to the number of items in the table (number of players) end function
print what the function randomplr returns |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 10 Jan 2013 02:24 PM |
Oh i get it, but another question:
for _,v in pairs(game.Players:GetPlayers()) do end
print(#v) will that print a number of the players in game? |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 10 Jan 2013 02:31 PM |
#game.Players:GetChildren()
That will. |
|
|
| Report Abuse |
|
|
|
| 10 Jan 2013 02:40 PM |
function Players() return game.Players.NumPlayers end
function RandomPlayer() if Players() >= 1 then return game.Players:GetChildren()[math.random(1,Players())] end end
|
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 10 Jan 2013 03:04 PM |
| You can also use the NumPlayers property like ^ did |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 10 Jan 2013 03:10 PM |
| I laik doing it universal way. I still don't understand why roblox should waste their time on little properties like NumPlayers, instead of fixing that GetMouse.MouseIcon problem. |
|
|
| Report Abuse |
|
|
|
| 10 Jan 2013 11:02 PM |
#game.Players:GetChildren() would return the number of objects in players. game.Players.NumPlayers returns the exact number of players in the game :D |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Jan 2013 01:14 AM |
| Well you can't have player anywhere else, anyway. |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Jan 2013 05:01 AM |
| Which idiot would do that.... We have already enough unused place in Lighting. |
|
|
| Report Abuse |
|
|
1WOOF1
|
  |
| Joined: 03 May 2009 |
| Total Posts: 20682 |
|
| |
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Jan 2013 05:11 AM |
| Well yeah, as I said, idiots does. |
|
|
| Report Abuse |
|
|