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 » Scripting Helpers
Home Search
 

Re: How to pick a random player?

Previous Thread :: Next Thread 
ToonU is not online. 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
Candymaniac is not online. Candymaniac
Joined: 08 Oct 2009
Total Posts: 8985
16 Sep 2012 10:30 AM
local yes = game.Players:GetChildren()
local math = math.random(1,#yes)

local Player = yes[math]

☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
16 Sep 2012 10:53 AM
local player=math.random(1,game:GetService("Players").NumPlayers)
Report Abuse
jobro13 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
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
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
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 is not online. 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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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 is not online. 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 is not online. 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
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
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 is not online. ToonU
Joined: 15 Aug 2011
Total Posts: 6303
16 Sep 2012 11:57 AM
Same output.

-Kevin
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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