Wittiest
|
  |
| Joined: 02 Mar 2009 |
| Total Posts: 9665 |
|
|
| 13 Feb 2016 02:12 AM |
The following code is functional, but I am a noob at efficiently. I'd like for my code to be more readable and concise. Could anyone show me a better way to do this? ------------- Team1 = "Crimson" Team2 = "Cyan"
game.Players.PlayerAdded:connect(function(plr) local num = game.Players.NumPlayers local rand = math.random(1,2) if num < 2 then if rand == 1 then plr.TeamColor = game.Teams[Team1].TeamColor else plr.TeamColor = game.Teams[Team2].TeamColor end else local var = '' for _,v in pairs(game.Players:GetChildren()) do if v.Name ~= plr.Name then var = v.TeamColor end end if var == Team1 then plr.TeamColor = game.Teams[Team2].TeamColor else plr.TeamColor = game.Teams[Team1].TeamColor end end end) |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2016 02:14 AM |
local num = #game.Players.NumPlayers*
|
|
|
| Report Abuse |
|
|
|
| 13 Feb 2016 02:14 AM |
Thought it was local num = game.Players:GetChildren() lmao. My bad.
|
|
|
| Report Abuse |
|
|
Wittiest
|
  |
| Joined: 02 Mar 2009 |
| Total Posts: 9665 |
|
|
| 13 Feb 2016 02:20 AM |
| Would really love some tips on making this code more concise. It is junky and nooby like me |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2016 02:21 AM |
What are you trying to accomplish via this script? As I can't be bothered going through it and understanding it, lol.
|
|
|
| Report Abuse |
|
|
Wittiest
|
  |
| Joined: 02 Mar 2009 |
| Total Posts: 9665 |
|
|
| 13 Feb 2016 02:23 AM |
| My server will only have two players. I want them randomly assigned to team 1 or team 2, but obviously I need one of them on Team1 and the other on Team2. |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2016 02:24 AM |
| What are you trying to do? Just shuffle the teams up? |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2016 02:26 AM |
Oh I see, you actually don't need a script at all
Under game.Teams.TeamName check 'AutoAssignable' and the teams will be balanced for you.
http://wiki.roblox.com/index.php?title=API:Class/Team/AutoAssignable |
|
|
| Report Abuse |
|
|
Wittiest
|
  |
| Joined: 02 Mar 2009 |
| Total Posts: 9665 |
|
|
| 13 Feb 2016 02:26 AM |
Synonymous to how in this game when a player is teleported to a server they are put as either the white or black chess player: http://www.roblox.com/games/95041893/Chess
I am trying to do that in scripting and I feel like I am over complicating it |
|
|
| Report Abuse |
|
|
|
| 13 Feb 2016 02:26 AM |
function setTeam(player) local TeamColours = {"Cyan", "Crimson"} if #game.Players:GetChildren() <= 2 then local team = TeamColours[math.random(1, #TeamColours)] player.TeamColor = BrickColor.new(team) local num = 0 for i, v in pairs (TeamColours) do num = num + 1 if v == team then num = 0 table.remove(TeamColours, num) break end end end end for _, player in pairs (game.Players:GetChildren()) do if player then setTeam(player) end end
|
|
|
| Report Abuse |
|
|
|
| 13 Feb 2016 02:31 AM |
My mistake: put "local TeamColours = {"Cyan", "Crimson"}" outside of the function.
|
|
|
| Report Abuse |
|
|