Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to randomly pick a player? [closed]

Asked by 5 years ago

This question already has an answer here:

How can i make a Script to choose a random player?

I am looking to make a game where there are teams, there would be a team of 1 person then a team of 3 people against each other. I am trying to make a system that randomly selects a player to be the team of 1 then puts the rest on the other team. Any help on how to do this?

Marked as Duplicate by Shawnyg

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local players = game:GetService("Players"):GetPlayers()

local randomPlayer = players[math.random(1, #players)]

math.random(1, #players) will get a random number between 1 and (however many players are in the server), and running a array[number] will get the (number)'th value in the array

Ad