How to I pick 2 random objects or players

ok this should be pretty simple, i just do not know how to properly format this

I know how to pick one random

local randomequation = math.random(1, #Players)
		local chosenone = Players[randomequation]

please tell me if you know anything
Thanks!

2 Likes

Could you elaborate? What do you mean properly format…?

I’ve tried like something where a make a folder and then it randomly picks from the folder and then it’d pick another one from the folder once it was removed, that got really messy fast, so I deleted everything and restarted,
I’m not sure if there’s a way to pick 2 random players

To pick two random objects without picking the same one again, you can do something like this:

local playerTable = game:GetService("Players"):GetPlayers()
local randomPlayer1 = playerTable[math.random(1, #playerTable)] -- selecting our first random player

table.remove(playerTable, table.find(playerTable, randomPlayer1)) -- removing the player we got in the above statement, from the table

local randomPlayer2 = playerTable[math.random(1, #playerTable)] -- selecting our second random player

And you are done! To check if there are any players left in playerTable, you can use an if statement to check if the length of the table is 0.

3 Likes

I forgot that creating tables in scripts was still a thing , I haven’t coded in months, lol

1 Like