How Would I Be Able To Get 3 Players From Each Team Randomly

I’m trying to make it so i can get 3 players from each team [4 teams in total] and make them a murderer, how would I go by doing this

trying to make it so if there’s a even amount of players there’s a even amount of murderers for each team, the game holds 12 on each team, if there’s 10,9,6 players on a team etc the murders go down to 1

–// Spawn Players And Assigning Teams

–// Assign Team Function

local Game = game
local Teams = Game:GetService("Teams")
local RandomObject = Random.new()

local function GetPlayersFromTeams(NumberOfPlayers) --Number of players to fetch from each team.
	local Results = {} --Stores all of the results.
	for _, Team in ipairs(Teams:GetTeams()) do --Iterate over each team.
		Results[Team] = {} --Create a table entry for each team.
		local TeamPlayers = Team:GetPlayers() --Get the team's players.
		for _ = 1, math.min(NumberOfPlayers, #TeamPlayers) do --Select minimum of given number or team's population of players.
			local TeamPlayer = table.remove(TeamPlayers, RandomObject:NextInteger(1, #TeamPlayers)) --Get random team player.
			table.insert(Results[Team], TeamPlayer) --Insert random player into results table.
		end
	end
	return Results --Return results back to the caller.
end

Here’s a multi-purpose function that you can use to grab any number of players from each team.

The function returns a dictionary of teams (as keys/fields) and player arrays (as values).

1 Like