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 » Scripters
Home Search
 

Re: Team Rebalance?

Previous Thread :: Next Thread 
walkman057 is not online. walkman057
Joined: 02 Dec 2014
Total Posts: 250
09 Aug 2015 08:52 PM
I am attempting to make a team rebalance script... but I can't seem to get it. Here is what I got:

plrs = game.Players:GetPlayers()
half = plrs/4
tic = 0

red = "Bright red"
blue = "Bright blue"
green = "Bright green"
yellow = "Bright yellow"

for _,v in pairs (plrs) do
tic = tic + 1
if tic < half then
v.TeamColor = BrickColor.new(red)
elseif tic < half*2 then
v.TeamColor = BrickColor.new(blue)
elseif tic < half*3 then
v.TeamColor = BrickColor.new(green)
else
v.TeamColor = BrickColor.new(yellow)
end
end


The output says this:

Workspace.Script:4: attempt to perform arithmetic on global 'plrs' (a table value)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Aug 2015 08:54 PM
#plrs / 4

Also this won't always randomize the teams, I made a function a while back that does what you want plus optional randomization if you want it.
Report Abuse
walkman057 is not online. walkman057
Joined: 02 Dec 2014
Total Posts: 250
09 Aug 2015 09:02 PM
@cnt

Could you please send me the link? That might be helpful...
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
09 Aug 2015 09:03 PM
function Rebalance(random)
local players = game.Players:GetPlayers()
local teams = game.Teams:GetChildren()
local plrs
if random then
plrs = {}
for i = 1,#players do
table.insert(plrs, table.remove(players, math.random(#players)))
end
else
plrs = players
end
for i,v in pairs(plrs) do
v.TeamColor = teams[i%#teams+1].TeamColor
end
end

--Will this do the trick?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Aug 2015 09:05 PM
local randomizeTeams = function(teamColors, randomize)
local players = game.Players:GetPlayers();
for key = 1, #players do
table.remove(players, randomize and math.random(#players) or 1).TeamColor = teamColors[((key - 1) % #teamColors) + 1];
end
end;

randomizeTeams({game.Teams.TeamA.TeamColor, game.Teams.TeamB.Teamcolor}, true);

I actually just remade the function right now so sorry if there are any dumb errors.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
09 Aug 2015 09:09 PM
@cnt I found one. It's a problem with your random argument. **hint** **hint**
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
09 Aug 2015 09:10 PM
Jk I dun see any qq
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Aug 2015 09:11 PM
I should have named the function "balanceteams" or something, any I found a problem -.-
'TeamB.Teamcolor' - Lowercase c in color
Report Abuse
walkman057 is not online. walkman057
Joined: 02 Dec 2014
Total Posts: 250
09 Aug 2015 09:15 PM
Thanks guys!!
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
09 Aug 2015 09:17 PM
@cnt Personally I think this looks better:

function rebalance(randomize, players, teams)
players = players or game.Players:GetPlayers()
teams = teams or game.Teams:GetChildren()
for i = 1, #players do
table.remove(players, randomize and math.random(#players) or 1).TeamColor = teams[i%#teams+ 1].TeamColor
end
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Aug 2015 09:19 PM
That won't work correctly though, so if aesthetics > usability then sure :)
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Aug 2015 07:55 AM
Why wouldn't it? I only modified yours for the arguments and such...
Report Abuse
walkman057 is not online. walkman057
Joined: 02 Dec 2014
Total Posts: 250
10 Aug 2015 09:33 AM
So, I added a part that teleports players to random spawns, but I am not sure how to test it... Can someone tell me if it would work?

local randomizeTeams = function(teamColors, randomize)
local players = game.Players:GetPlayers();
for key = 1, #players do
table.remove(players, randomize and math.random(#players) or 1).TeamColor = teamColors[((key - 1) % #teamColors) + 1];
end
wait(1)
for _, v in next, players do
local spawnzz = workspace.Spawns:GetChildren();
local spawn = table.remove(spawnzz, math.random(1,#spawnzz));
v.Character.Torso.CFrame = spawn.CFrame * CFrame.new(0,3,0);
end
end;

randomizeTeams({game.Teams.TeamA.TeamColor, game.Teams.TeamB.TeamColor, game.Teams.TeamC.TeamColor, game.Teams.TeamD.TeamColor}, true);
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Aug 2015 10:51 AM
Try my function to randomize teams, do spawning in a separate function (and use my 2nd version, it's much better than the 1st XD)
Report Abuse
walkman057 is not online. walkman057
Joined: 02 Dec 2014
Total Posts: 250
10 Aug 2015 11:00 AM
So, like this?


function rebalance(randomize, players, teams)
players = players or game.Players:GetPlayers()
teams = teams or game.Teams:GetChildren()
for i = 1, #players do
table.remove(players, randomize and math.random(#players) or 1).TeamColor = teams[i%#teams+ 1].TeamColor
end
end

for _, v in next, players do
local spawnzz = workspace.Spawns:GetChildren();
local spawn = table.remove(spawnzz, math.random(1,#spawnzz));
v.Character.Torso.CFrame = spawn.CFrame * CFrame.new(0,3,0);
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Aug 2015 11:09 AM
Don't forget to call the function.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Aug 2015 02:51 PM
warspy, no you modified more
'i%#teams+ 1'

You made it not work properly silly
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Aug 2015 03:45 PM
Why wouldn't it not work properly...
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Aug 2015 03:49 PM
Because the math is wrong, am I not making it clear enough?
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Aug 2015 04:03 PM
But _what_ is wrong with the math???
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Aug 2015 04:17 PM
It is able to result to 0, and lua arrays start at 1
Report Abuse
walkman057 is not online. walkman057
Joined: 02 Dec 2014
Total Posts: 250
10 Aug 2015 05:04 PM
So, what would the correct script look like?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Aug 2015 05:35 PM
I already gave you one.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Aug 2015 05:50 PM
How can it result in 0...


1%4+1 == 2
2%4+1 == 3
3%4+1 == 4
4%4+1 == 1



The math never results in 0 (4 is an example, 4 can be any number and it still won't...)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Aug 2015 06:02 PM
Woops, I thought the #teams + 1 were grouped (parenthesized)
Anyways yours starts by choosing team 2, then going on from there which might not really be a good thing (yes you can start the loop at 0 yada yada)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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