Okay, so I am making a game using aspects of lua I have never come across before. I want to put two people into the team of 'Hunters', and the rest in 'Runners'. The hunters should be random. Could anyone give me a hand with this one?
Well to get players teamcolor it requires to do player.TeamColor
and to set it you can do player.TeamColor = team.TeamColor
so do this to set and check colors:
local hunters = game.Teams.Hunters --Add a team called hunters local runners = game.Teams.Runners --Same thing for runners local lobby = game.Teams.Lobby --Same thing again --To get the two hunters for i = 1, 2 do local plr = game.Players:GetChildren()[math.random(1, #game.Players:GetChildren())] repeat plr = game.Players:GetChildren()[math.random(1, #game.Players:GetChildren())] until plr.TeamColor == lobby.TeamColor --This works if you have a variable for a team Lobby, can be changed easily. Also the repeat until thing is to make sure the player isn't assigned to another team and so that it finds two different hunters plr.TeamColor = hunters.TeamColor end --To set the rest to runners for _, v in pairs(game.Players:GetChildren()) do --If you are not familiar with for in pairs it loops through the table and _ is the index of the table and the v is the current value at that index if v.TeamColor == lobby.TeamColor then v.TeamColor = hunter.TeamColor end end
This SHOULD work, otherwise comment any errors
local hunters = game.Teams.Hunters local lobby = game.Teams.Lobby local runners = game.Teams.Runners if game.Players<=3 then local players = game.Players:GetPlayers() local one = table.remove(players, math.random(#players)); local two = table.remove(players, math.random(#players)); players.TeamColor = hunters.TeamColor for i,v in pairs(game.Players:GetChildren()) do if v.TeamColor==lobby.TeamColor then v.TeamColor=hunters.TeamColor end end end
Should this work then?