Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I select multiple random players?

local Pick = 1
local function RandomPlr()
	local plrs = game:GetService("Players"):GetPlayers()
	return plrs[math.random(1, #plrs)]
end

My current function selects one player out of all players. "Pick" is supposed to be the amount of random players I pick. How do I make it so, if Pick was equal to 2, it picks two random players? (Also it doesn't matter if the same person is picked more than once, as long as it picks multiple random players)

1 answer

###Just make a variable for the other player.

local Pick = 1
local function RandomPlr()
    local plrs = game:GetService("Players"):GetPlayers()
    local player1 = plrs[math.random(#plrs)]
    local player2 = plrs[math.random(#plrs)]
    return {player1, player2)
end

local randomPlayers = RandomPlr()

print(randomPlayers[1], randomPlayers[2])

2 comments

0

You forgot to add a close bracket at the end of the line for lines 4 and 5

0

correct lol.

This discussion is preserved as it was. New answers, comments, and votes are closed.