✓ Accepted answer
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()
local currentTeams = game.Teams:GetChildren()
local randomPlayer = currentPlayers[math.random(1,#currentPlayers)]
local randomTeam = currentTeams[math.random(1,#currentTeams)]
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
1 comment
:D