How would I make a team randomizer? Im making a pacman inspired multiplayer game but have no clue how i wouldrandomly assign 3 players to the ghost team and 1 player to the pacman team, can someone help?
Thanks for reading
How would I make a team randomizer? Im making a pacman inspired multiplayer game but have no clue how i wouldrandomly assign 3 players to the ghost team and 1 player to the pacman team, can someone help?
Thanks for reading
You can just choose randomly 1 player to be on the pacman team. I haven’t tested the code so I can’t guarantee that it will work. Please tell me if it doesn’t.
local Teams = game:GetService("Teams")
local chosenPacman = game.Players[math.random(1, #game.Players:GetPlayers())]
chosenPacman.Team = Teams.PacmanTeam
for _, player in pairs(game.Players:GetPlayers()) do
if player.Team ~= Teams.PacmanTeam then
player.Team = Teams.GhostTeam
end
end
Is there a way I can make sure the script just runs when there are multiple players? So that I can test properly
What do you mean by that? If you want to test with multiple players, you can run a test server from the Test tab in studio.
I assume you’re trying to make a round based game? In that case you can do a while true do loop, and every time a round starts you can check if there are enough players.
local Players = game:GetService("Players")
while true do
--checks if there are more than 4 players
if #Players:GetPlayers() >= 4 then
--assign the team here
end
end