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: Pick two random people.

Previous Thread :: Next Thread 
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 04:28 PM
Nothing too complicated, just a example that I can edit.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 04:29 PM
local allPlayers = Game.Players:GetPlayers();
local player1, player2;

if #allPlayers >= 2 then
player1 = table.remove(allPlayers, math.random(#allPlayers));
player2 = allPlayers[math.random(#allPlayers)];
end
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
28 May 2014 04:34 PM
P = Game.Players:GetPlayers()
local r1 = P[math.random(1,#P)]
table.remove(P,r1)
if #P > 0 then
local r2 = P[math.random(1,#P)]
else
end

Not tested
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
28 May 2014 04:35 PM
ninja'd(or whatever you call it)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 04:36 PM
You still have a chance for a interval is empty error and putting the r2 local variable in the if scope is kinda useless if they don't plan on putting their code in the if scope--since they won't be able to access r2.
Report Abuse
Argelius is not online. Argelius
Joined: 19 Jul 2010
Total Posts: 4047
28 May 2014 04:36 PM
This should be in the "Scripting Requests" forum

Oh wait we don't have one

so this shouldn't exist
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 04:43 PM
@cnt, just a quick question, was does the symbol ; do?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 04:43 PM
In Lua? Not much, it's not required but it's just a habit.
Report Abuse
Argelius is not online. Argelius
Joined: 19 Jul 2010
Total Posts: 4047
28 May 2014 04:44 PM
It is a required symbol in other programming languages but not Lua, I believe.
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 05:07 PM

So I would edit the random chosen players using the variables Player1 and 2?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 05:09 PM
Assuming 2 or more people are in the game and you run that, then yes, player1 and player2 will be the actual player object.

player1.Character.Humanoid.WalkSpeed = 100 or whatever
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 05:18 PM
So this would print The "first pair is randomname1, randomname2"

local allPlayers = Game.Players:GetPlayers();
local player1, player2;
local chosen = {player1, player2}
if #allPlayers >= 2 then
player1 = table.remove(allPlayers, math.random(#allPlayers));
player2 = allPlayers[math.random(#allPlayers)];
print( "The fisrt pair is", unpack(squares))
end
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 05:19 PM
So this would print The "first pair is randomname1, randomname2"

local allPlayers = Game.Players:GetPlayers();
local player1, player2;
local chosen = {player1, player2}
if #allPlayers >= 2 then
player1 = table.remove(allPlayers, math.random(#allPlayers));
player2 = allPlayers[math.random(#allPlayers)];
print( "The fisrt pair is", unpack(chosen))
end

Sorry, learning this also off the Wiki.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 05:20 PM
No.

local allPlayers = Game.Players:GetPlayers();
local player1, player2;
if #allPlayers >= 2 then
player1 = table.remove(allPlayers, math.random(#allPlayers));
player2 = allPlayers[math.random(#allPlayers)];

local chosen = {player1, player2}
print( "The fisrt pair is", unpack(chosen)) --squares?
end
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 05:21 PM
Yeah, I fixed it. Thanks.
Report Abuse
Krauzz is not online. Krauzz
Joined: 24 Sep 2012
Total Posts: 104
28 May 2014 05:27 PM
Um, also you should use a loop to make sure the random players aren't the same player

local player1
local player2
repeat
player1 = game:service'Players':GetPlayers()[(math.random(#game:service'Players':GetPlayers())]
player2 = game:service'Players':GetPlayers()[(math.random(#game:service'Players':GetPlayers())]
until player1 ~= player2
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 05:29 PM
No, that's terribly inefficient and my way already deals with that.
Report Abuse
Krauzz is not online. Krauzz
Joined: 24 Sep 2012
Total Posts: 104
28 May 2014 05:34 PM
I didn't see your latter post, sry
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 05:38 PM
My first post even did that, so yeah.
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 07:44 PM
@cnt, is their a Lua index? For stuff such as #s and other Lua symbols?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 07:46 PM
"#" is just an operator to get the length-of.
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 07:49 PM
Lol, so you could do:
namelenth = game.Players:FindFirstChild("Seizurezxzz")
print (#namelenth)
prints: 11
Thats just what I think of when you say that.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 May 2014 07:50 PM
No, because if namelenth isn't nil, it would be a userdata.

print(#namelenth.Name)
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
28 May 2014 07:51 PM
Well strings aren't considered tables in lua, but that does still work so yes.
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
28 May 2014 07:52 PM
Thanks.
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