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
 

Teams

Previous Thread :: Next Thread 
sunday1520 is not online. sunday1520
Joined: 23 Aug 2012
Total Posts: 693
22 Sep 2013 04:30 PM
Alright, so ive got my teams all set up. Theres only two. How do i make it so that when a player is added, it places the player on the team with the least amount of players? or if the teams are equal, just places them on a random team. Ive usually scripted tycoons and other single player games, so this "teams" thing is really new to me. Can anyone help me out?
Report Abuse
ZachBloxx is not online. ZachBloxx
Joined: 26 Jun 2013
Total Posts: 2833
22 Sep 2013 04:32 PM
If you can script a tycoon you can script this.
Report Abuse
sunday1520 is not online. sunday1520
Joined: 23 Aug 2012
Total Posts: 693
22 Sep 2013 04:33 PM
Haha funny i thought the same thing, but really i dont know. Theres no set values anywhere i can find determining what team a player is on. And without a value i have no clue how to track these things, so can you help me out.
Report Abuse
AnarchyMaster is not online. AnarchyMaster
Joined: 16 Sep 2013
Total Posts: 1045
22 Sep 2013 04:33 PM
You've scripted a tycoon, but you can't do extremely basic table math? Mk...
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
22 Sep 2013 04:34 PM
local team1 = game.Teams["Team1's Name Here"]
local team2 = game.Teams["Team2's Name Here"]

game.Players.PlayerAdded:connect(function(player)
if #team1:GetChildren() < #team2:GetChildren() then
player.TeamColor = team1.TeamColor
elseif #team2:GetChildren() < #team1:GetChildren() then
player.TeamColor = team2.TeamColor
elseif #team1:GetChildren() == #team2:GetChildren() then
local randomizer = math.random(1,2)
if randomizer == 1 then
player.TeamColor = team1.TeamColor
else
player.TeamColor = team2.TeamColor
end
end
end)

~rekt get
Report Abuse
sunday1520 is not online. sunday1520
Joined: 23 Aug 2012
Total Posts: 693
22 Sep 2013 04:36 PM
Anarchy, tycoons are much different. Its not the tables that throw me off, its the fact i cant find a set value determining a players team therefore there is no simple way to count or place players. Unless of course i create by own self-adding table which was more work than i felt like doing. Therefore i went to the forums.
Report Abuse
ZachBloxx is not online. ZachBloxx
Joined: 26 Jun 2013
Total Posts: 2833
22 Sep 2013 04:38 PM
I'll just be honest, I think you use free model tycoon kits. Because if you can script a tycoon, this shouldn't be too hard.

local Team1,Team2 = game:GetService('Teams').Team1,game:GetService('Teams').Team2

local TeamsTab = {Team1,Team2}

local function getTeamPlayers(teamColor)
local count = 0
for i,v in pairs(game.Players:GetPlayers()) do
if v.TeamColor == teamColor then
count = count + 1
end
end
return count
end

game.Players.PlayerAdded:connect(function(Player)
if getTeamPlayers(Team1.TeamColor) > getTeamPlayers(Team2.TeamColor) then
Player.TeamColor = Team2.TeamColor
elseif getTeamPlayers(Team1.TeamColor) < getTeamPlayers(Team2.TeamColor) then
Player.TeamColor = Team1.TeamColor
else
Player.TeamColor = TeamsTab[math.random(1,#TeamsTab)].TeamColor
end
end)
Report Abuse
sunday1520 is not online. sunday1520
Joined: 23 Aug 2012
Total Posts: 693
22 Sep 2013 04:44 PM
Actually i dont use free models to make a tycoon. ITs a totally different thing. Ive never tried this before thats why i cant do it. Cloning and removing products to recall them when a players money value is a certain number or higher is a lot different than tracking players on teams. Just thought id put that out there.
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
22 Sep 2013 04:55 PM
Teams,Amount = game:GetService("Teams"):GetChildren(),{}

for _,Team in pairs(Teams) do
for _,Player in pairs(game:GetService("Players"):GetPlayers()) do
if Player.TeamColor == Team.TeamColor then
Amount[TeamColor] = Amount[TeamColor] + 1
end
end
end

Okay, so that's part of what I came up with. My computer is broken right now, so I can't test a way to find the max value of a table, so someone will have to fill me in.
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