GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
|
| 16 Mar 2014 12:03 PM |
I have this...
table = {"Player2","Player1"} random = math.random(1,#table) Picked = table[random] if Picked == table[1] then print("Hi Player2") elseif Picked == table[2] then print("Hi player1") wait() end
I am just questioning if it's possible to have it as EVERY player who is in the game... and maybe go by time of entry... So say I join the game first and then "Bob" joins then "Bobby" joins. It would be
table = {"GamingOwl","Bob","Bobby"}
It would be fine if it was a random table too.... I just need it as a table... |
|
|
| Report Abuse |
|
|
GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
| |
|
|
| 16 Mar 2014 12:13 PM |
Why'd you need to make a separate table??? Use :GetChildren() on game.Players. It returns a table. |
|
|
| Report Abuse |
|
|
GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
|
| 16 Mar 2014 12:17 PM |
I'm trying to choose certain people... If I use math.random on plain players like...
local players = game.Players:GetPlayers() local ran = players[math.random(#players)]
then it could choose the same person twice. (Forgot to mention in the final script it chooses 2 people.) So I want to use a table to make sure it doesn't choose the same person twice.... |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:19 PM |
add this to top of script
math.randomseed(tick())
#nerdsunited |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:20 PM |
Well, then I guess what you want is to use table.insert? http://wiki.roblox.com/index.php/Function_dump/Table_manipulation#table.insert |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:20 PM |
Players = {}
function PlayerAdded() Players = game.Players:GetChildren() for i = 1, #Players do print(Players[i].Name) end end
game.Players.PlayerEntered:connect(PlayerAdded)
for _,v in pairs (game.Players:GetChildren()) do PlayerAdded() end
This will print the name of the players in the game everytime someone joins.
Look, I do things now! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
|
| 16 Mar 2014 12:26 PM |
Thank you everyone. Thank you blue for the script.... I think.... It's gonna take some time to play around with it and make it work to what I want to do for the final script... but it will be worth it in the end! |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:34 PM |
@filip use GetPlayers()
@blue What if a player leaves?
function game.Players.PlayerRemoving:connect(function(p) for i = 1,#Players do if i == p then table.remove(Players[i]) end end end)
Something like that I think? |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:43 PM |
@War
It resets the table every time a player joins
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:43 PM |
@War Oh, nevermind, I see what you were getting at. That code you gave for PlayerRemoved() should work with mine.
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:43 PM |
| May I ask, what is the difference between using GetPlayers() and GetChildren() on game.Players? Is GetPlayers() faster or why is it better? o.o |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:44 PM |
/\ if a value or something is inserted into game.Players for any reason,youll have "Value" in your table XD |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:48 PM |
GetChildren() returns EVERYTHING inside game.Players
GetPlayers() only returns Player objects.
Like what island said.
If I have an int value or a model inside game.Players (Like game.Players.Model)
GetChildren() would return the Players + the Model. GetPlayers() would return just the Players.
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:51 PM |
Oh... I always thought game.Players was locked so you couldn't insert anything there :P Thanks. |
|
|
| Report Abuse |
|
|
GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
|
| 16 Mar 2014 12:54 PM |
Okay... Me again... Just wondering how you would choose which does which?
table = {"Player2","Player1"} random = math.random(1,#table) Picked = table[random] if Picked == table[1] then print("Hi Player2") elseif Picked == table[2] then print("Hi player1") wait() end
Like this I could choose if it was table 1 or 2... How can I do it with yours?
|
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 12:59 PM |
The same way.
When the server stats: Players = {}
When players join, the table now says: Players = {Player1, Player2, blueboy112, Telamon}
You can get a player by:
Players[Number you want]
So,
Players[1] Would return 'Player1' and Players[3] would return 'blueboy112'
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
| |
|
|
| 16 Mar 2014 01:04 PM |
function PickPlayer() local Picked = Players[math.random(1,#Players)] print("Hi "..Picked.Name) end
function PlayerAdded() Players = game.Players:GetChildren() for i = 1, #Players do print(Players[i].Name) end PickPlayer() end
game.Players.PlayerEntered:connect(PlayerAdded)
game.Players.PlayerRemoved:connect(function(p) for i = 1, #Players do if Players[i] == p then table.remove(Players[i]) end end end)
for _,v in pairs (game.Players:GetChildren()) do PlayerAdded() end
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 01:05 PM |
That's the full script.
My script + War's section + It picks a player and prints "Hi ThePlayersName"
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 01:06 PM |
(It only says Hi once that player has been randomly picked)
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
|
| 16 Mar 2014 01:09 PM |
| I just realized your script activates with a player enters... I don't want the script to trigger when the player enters. I want be able to access the table later on in the script.... If it is just adding to the table when the person enters then it's fine... If not then I need something different... >_< |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 01:12 PM |
It updates the same table.
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2014 01:12 PM |
Ah woops. Forgot to add
Players = {}
To the beginning of the script.
That's the main table that gets updated.
Hire me! http://www.roblox.com/Forum/ShowPost.aspx?PostID=128214378 |
|
|
| Report Abuse |
|
|
GamingOwl
|
  |
| Joined: 18 Feb 2014 |
| Total Posts: 350 |
|
| |
|