• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Selecting 2 Players individually with math.random?

dejame

New Member
Joined
Jan 21, 2013
Messages
12
Reaction score
0
Hello everyone!

Well, I got myself stuck with this, I would like to use math.random to select 2 Players and teleport them to 2 different Locations...
So, this means that I can't use list[math.random(2, #list)] because then I will have to teleport them both to the same location.

The real problem is that if I use math.random 1, there is a chance to select the same player 2 times. Example:

local one = list[math.random(1, #list)]
local two = list[math.random(1, #list)]

I don't know if there is a way to exclude the one after selecting him from the list and then selecting number two...
This thing is really breaking my brain! Does anyone knows a way to do this? :confused:

Thanks!
 
Lua:
local r1 = math.random(#list)
local player1 = list[r1]
table.remove(list, r1)
local player2 = list[math.random(#list)]
Otherwise you can repeat until loop, until player 1 is unequal to player 2, but above should work.
 
I'll try it out, Thanks a lot!


EDIT: Working! Another step forward in my script, Thank you! :p
 
Last edited:
Back
Top