Help with a team randomizer

I am currently making a zombie survival game, and there are 2 main teams, the “Humans” and the “Zombies”, every time a match starts, if the server has at least 2 players then 30% (rounded up) of the players in the server will spawn as a zombie, i know how to determine the amount of players that will become zombies but i don’t know how to randomly chose those players with a server script, can anyone help me out?

Are you looking for something like this?

for _, i in pairs(game.Players:GetPlayers()) do
	local myVariable = math.random(1, 10)
	if myVariable > 0 and myVariable < 4 then
		-- Spawn player as zombie
	end
end

i just found out that you can simply use this

local players = game:GetService("Players")
local PlayerAmount = #players:GetPlayers()
1 Like