How do I assign 1 Random Player to a Team

So i want to make a “1 random player is the killer” but i do not know how to do that. Can someone help me.

Anything is helpful

Very simple. Do this:

local players = game.Players:GetPlayers()
local killer = players[math.random(1, #players)]

You can then assign that player to a team.

let me try the script to see if it worked

how to i assign that player to the team

local players = game.Players:GetPlayers --we get the table of players in the game
local playerChosen = math.Random(1, #players) --we chose a random player

playerChosen.Team = game.Teams.killer
local Teams = game:GetService("Teams")
local killerteam = Teams.Killer -- Edit the killer team here!

local players = game.Players:GetPlayers()
local killer = players[math.random(1, #players)]

killer.Team = killerteam
killer.Team.TeamColor =  killerteam.TeamColor

it didnt work. I dont know whats happen because the random player are not assign to the team

Is the script a client or server script?

You need to test it with more than 1 person, at least 2

server script.

ignore this

This text will be hidden

ok let me try that. thanks man

just pick 2 players in the test section and you’re good to go

it still didnt work. i took yall advise but it just didnt work

i just now did that a while ago

Try this

local Teams = game:GetService("Teams")
local killerteam = Teams.Killer -- Edit the killer team here!

if #game.Players:GetPlayers() < 2 then 
	repeat 
		wait() 
	until #game.Players:GetPlayers() > 1 --Will wait until there is more than 1 person in the server
end

local players = game.Players:GetPlayers()
local killer = players[math.random(1, #players)]

killer.Team = killerteam
killer.Team.TeamColor =  killerteam.TeamColor
2 Likes
killer.Neutral = false

Check this out: Player | Roblox Creator Documentation

ok i will try it right now. thanks

it worked thanks man. youre the best

2 Likes