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: Fraction of the number of players

Previous Thread :: Next Thread 
TheGoldenToilet is not online. TheGoldenToilet
Joined: 23 Apr 2011
Total Posts: 124
13 Mar 2014 09:51 AM
So, I need to make a script where 1/3 of the players go to team blue, and 2/3 of the players go to the team red.
How would I do that? I looked on the wiki but I didn't find anything. Anyone think they can help?
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
13 Mar 2014 10:15 AM
for i = 1, #game.Players.NumPlayers/3 do
local randomplayer = game.Players:GetPlayers()[math.random(1,game.Players.NumPlayers)]
if randomplayer.TeamColor ~= (INSERTTEAMCOLORHERE) then
randomplayer.TeamColor = (WHATEVERTEAMCOLOR)
end
end

You get the idea. This does not search again if the player is already that team color.
Report Abuse
TheGoldenToilet is not online. TheGoldenToilet
Joined: 23 Apr 2011
Total Posts: 124
13 Mar 2014 10:25 AM
Thanks! I can't test it right now since I don't have 3 computers, but I could probably try with 2
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
13 Mar 2014 10:28 AM
You don't need 3 computers... Studio -> Tools -> Test -> Start Server (loads, in new window;) Studio -> Tools -> Test -> Start Player (3 times)
Report Abuse
TheGoldenToilet is not online. TheGoldenToilet
Joined: 23 Apr 2011
Total Posts: 124
13 Mar 2014 10:36 AM
Oh cool! I didn't know about that. Thank you all!
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
13 Mar 2014 10:43 AM
No problem!
Report Abuse
Cawlonee is not online. Cawlonee
Joined: 03 Mar 2014
Total Posts: 2687
13 Mar 2014 11:01 AM
Evolved script will check the same player again.

You should use a table of players and remove them has they get their team.

His script will run the for loop for the same player, it just doesn't do anything.

This will make some players not receive a team.
Report Abuse
Cawlonee is not online. Cawlonee
Joined: 03 Mar 2014
Total Posts: 2687
13 Mar 2014 11:05 AM
players,team1,team2 = game.Players:GetChildren(),{},{}

t1num = math.ceil(#players/3)

for i=1,t1num do
table.insert(team1,players[i])
end

for i=t1num+1,#players do
table.insert(team2,players[i]
end

for i,v in pairs(team1)do
v.TeamColor = BrickColor.new("Color")
end

for i,v in pairs(team2)do
v.TeamColor = BrickColor.new("Color")
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
13 Mar 2014 11:07 AM
Cal, you complicate things...
Report Abuse
Cawlonee is not online. Cawlonee
Joined: 03 Mar 2014
Total Posts: 2687
13 Mar 2014 11:10 AM
I break my code up so anyone can understand.

He can condense it if he likes, at least it works.
Report Abuse
Cawlonee is not online. Cawlonee
Joined: 03 Mar 2014
Total Posts: 2687
13 Mar 2014 11:11 AM
--Here, I'll condense it a little.

players,team1,team2 = game.Players:GetChildren(),{},{}

t1num = math.ceil(#players/3)

for i=1,#players do
if i <= t1num then
table.insert(team1,players[i])
else
table.insert(team2,players[i])
end

for i,v in pairs(team1)do
v.TeamColor = BrickColor.new("Color")
end

for i,v in pairs(team2)do
v.TeamColor = BrickColor.new("Color")
end
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