Hi, so I made a simple intermission countdown as a textbox, but I want for it to randomly assign teams after teh countdown and then kill everyone so they spawn at the spawnpoint, here is my code for the countdown which changes teh status of something which ten updates the text to say the status of it:
local status = game.ReplicatedStorage:WaitForChild("Status") wait (5) status.Value = "Intermission - 60" Wait(1) status.Value = "Intermission - 59" Wait(1) status.Value = "Intermission - 58" Wait(1) status.Value = "Intermission - 57" Wait(1) status.Value = "Intermission - 56" Wait(1) status.Value = "Intermission - 55" Wait(1) status.Value = "Intermission - 54" Wait(1) status.Value = "Intermission - 53" Wait(1) status.Value = "Intermission - 52" Wait(1) status.Value = "Intermission - 51" Wait(1) status.Value = "Intermission - 50" Wait(1) status.Value = "Intermission - 49" Wait(1) status.Value = "Intermission - 48" Wait(1) status.Value = "Intermission - 47" Wait(1) status.Value = "Intermission - 46" Wait(1) status.Value = "Intermission - 45" Wait(1) status.Value = "Intermission - 44" Wait(1) status.Value = "Intermission - 43" Wait(1) status.Value = "Intermission - 42" Wait(1) status.Value = "Intermission - 41" Wait(1) status.Value = "Intermission - 40" Wait(1) status.Value = "Intermission - 39" Wait(1) status.Value = "Intermission - 38" Wait(1) status.Value = "Intermission - 37" Wait(1) status.Value = "Intermission - 36" Wait(1) status.Value = "Intermission - 35" Wait(1) status.Value = "Intermission - 34" Wait(1) status.Value = "Intermission - 33" Wait(1) status.Value = "Intermission - 32" Wait(1) status.Value = "Intermission - 31" Wait(1) status.Value = "Intermission - 30" Wait(1) status.Value = "Intermission - 29" Wait(1) status.Value = "Intermission - 28" Wait(1) status.Value = "Intermission - 27" Wait(1) status.Value = "Intermission - 26" Wait(1) status.Value = "Intermission - 25" Wait(1) status.Value = "Intermission - 24" Wait(1) status.Value = "Intermission - 23" Wait(1) status.Value = "Intermission - 22" Wait(1) status.Value = "Intermission - 21" Wait(1) status.Value = "Intermission - 20" Wait(1) status.Value = "Intermission - 19" Wait(1) status.Value = "Intermission - 18" Wait(1) status.Value = "Intermission - 17" Wait(1) status.Value = "Intermission - 16" Wait(1) status.Value = "Intermission - 15" Wait(1) status.Value = "Intermission - 14" Wait(1) status.Value = "Intermission - 13" Wait(1) status.Value = "Intermission - 12" Wait(1) status.Value = "Intermission - 11" Wait(1) status.Value = "Intermission - 10" Wait(1) status.Value = "Intermission - 8" Wait(1) status.Value = "Intermission - 7" Wait(1) status.Value = "Intermission - 6" Wait(1) status.Value = "Intermission - 5" Wait(1) status.Value = "Intermission - 4" Wait(1) status.Value = "Intermission - 3" Wait(1) status.Value = "Intermission - 2" Wait(1) status.Value = "Intermission - 1" Wait(2) status.Value = "Round starting, get ready!" wait(1)
I want it after this to randomly and evenly assign teams and then start the game so they are moved off of the lobby team.
May I suggest using for loops instead of the monstrosity of code you have, no offense?
for i = 60, 1, -1 do status.Value = "Intermission - " .. i wait(1) end wait(2) status.Value = "Round starting, get ready!" wait(1)
With that dealt with, you can randomly pick a player from the game by first getting all of the players using the GetPlayers function of the Players service and then alternate between putting them in the first team and then the second team (or more teams if you have more). The simplest case I'll be handling is evenly assigning players to two teams:
local list = game.Players:GetPlayers() local Teams = {game.Teams.Team1, game.Teams.Team2} for _ = 1, #list do local index = math.random(1, #list) -- randomly choose an index that leads to a player local player = list[index] -- gets the randomly chosen player player.Team = Teams[ (#list % 2) + 1 ] -- chooses player's team; explanation below table.remove(list, index) -- removes the player from the list so that they aren't chosen again end
#list % 2
finds the remainder when you divide #list
by 2. In the case of the numbers being whole numbers, the result is either 0 or 1. 1 is added so that it properly gets the index of the team in the Teams
table, so 0 becomes 1, and 1 becomes 2.
players = game:GetService("Players"):GetPlayers() for i=1, #players do local RandomNumber = math.random(1,however many teams you have) --start using if statements to assign different values of RandomTeam to different teams e.g. --if RandomNumber==1 then --AssignedTeam=game.teams.some_random_team players[i].team = AssignedTeam --insert code to kill player
The code you have is much longer than it needs to be. I recommend learning how to use loops in this context. https://developer.roblox.com/en-us/articles/Loops
Peep a video tutorial if you learn better that way - For Loops - Roblox Beginner Scripting #20 (AlvinBlox)
Now to randomly team the players, what I'd do is something along the lines of:
Good luck, and don't be afraid to ask more questions (with some formatting please).