ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
|
| 16 Sep 2012 10:28 AM |
I'm making a game show like game, I got it mostly scripted but for some reason I can't think of how to pick a random player from Players.. Little help? xD Thanks.
P.S: I don't need the full script, just a hint.
-Kevin |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 10:30 AM |
local yes = game.Players:GetChildren() local math = math.random(1,#yes)
local Player = yes[math]
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 10:53 AM |
| local player=math.random(1,game:GetService("Players").NumPlayers) |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 16 Sep 2012 10:54 AM |
Even shorter!
local player = game.Players[math.random(game.Players.NumPlayers)] |
|
|
| Report Abuse |
|
|
0LED
|
  |
| Joined: 15 Sep 2012 |
| Total Posts: 224 |
|
|
| 16 Sep 2012 10:56 AM |
s=game.Players[math.random(game.Players.NumPlayers)]
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ |
|
|
| Report Abuse |
|
|
ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
|
| 16 Sep 2012 11:01 AM |
Mind helping me put this into a message please?
msg.Text = "Player: ".. .." has been chosen."
.. :P
-Kevin |
|
|
| Report Abuse |
|
|
0LED
|
  |
| Joined: 15 Sep 2012 |
| Total Posts: 224 |
|
|
| 16 Sep 2012 11:03 AM |
... s=game.Players[m'ath.random(game.Players.NumPlayers)] msg.Text="Player: ..s.." has been chosen."
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ |
|
|
| Report Abuse |
|
|
ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
|
| 16 Sep 2012 11:04 AM |
Ok thought so, It seemed error prone to me.
Thanks! :D
-Kevin |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 11:35 AM |
jobro wins for most resource efficient script :P
¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests! |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 11:35 AM |
@0LED
that wouldn't work.. there are no numerically indexed objects in roblox instances.
¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests! |
|
|
| Report Abuse |
|
|
ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
|
| 16 Sep 2012 11:37 AM |
Yeah, did not work.
Gives a hint with no text.
-Kevin |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 11:42 AM |
local player = game.Players[math.random(game.Players.NumPlayers)] local m = Instance.new("Message", Workspace) m.Text = player.." has been chosen!"
Or whatever you want the message to say. And for a hint swap out the second line Message to Hint |
|
|
| Report Abuse |
|
|
ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
|
| 16 Sep 2012 11:45 AM |
Does not work, output:
12:44:20 - Workspace.Script:1: bad argument #1 to 'random' (interval is empty) 12:44:20 - Script "Workspace.Script", Line 1 12:44:20 - stack end
-Kevin |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 16 Sep 2012 11:47 AM |
@doombring42: Yea :D.
I always script like that. Efficiency FTW. |
|
|
| Report Abuse |
|
|
|
| 16 Sep 2012 11:48 AM |
s=game.Players:GetChildren()[math.random(game.Players.NumPlayers)]
¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests! |
|
|
| Report Abuse |
|
|
ToonU
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 6303 |
|
| |
|