So, I was making a game and in my mind, I wondered how you can change players team randomly. I know how to change it but not the scripts choice.
Is there one that have a approved answer?
I thought of something like this - "Example: game.Players.Player1.TeamColor
"
Mind putting everything like LocalPlayers and etc.
Thank you.
Yes, you can do this using the math.random
function. This function takes in two arguments and returns a randomized number between them.
Setup a randomized wait time, as well as the random character to change teams, and randomly manipulate the team they reside in.
local minWait = 10 local maxWait = 50 while wait(math.random(minWait,maxWait)) do local currentPlayers = game.Players:GetPlayers() --Collect all players local currentTeams = game.Teams:GetChildren() --Collect all teams --Get a random player, and a random team local randomPlayer = currentPlayers[math.random(1,#currentPlayers)] local randomTeam = currentTeams[math.random(1,#currentTeams)] --Manipulate the random player's team to the random team. randomPlayer.Team = randomTeam end
Note: In order to ensure the randomized team will not be the same as the randomized player's current team, you will have to add a while loop.
while randomPlayer.Team == randomTeam and wait() do randomTeam = currentTeams[math.random(1,#currentTeams)] end randomPlayer.Team = randomTeam