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

Tips on making an efficient random choosing system?

I could really use some advice, I'm a bit Intermediate when it comes to scripting and I hope some more advanced members could point me in the right direction. I'm basically making a game in which 2 random people are chosen to go into the middle, I know how to do this to an extent, but my question is how I can multiply the chance if someone, say, buys a game pass or something? I've done a lot of research and feel I have reached a dead end. I have never done this before. I would appreciate some advice on making a flawless choosing system that's fair and efficient, but also benefits anyone who buys a 2x chance gamepass.

Thank you so much!

EDIT: I'm going to accept an answer at the end of the night when replies stop, I'm choosing which one helps me most for my game. Thanks a ton.

2 answers

Here is a neat trick I use when selecting 2 random people.

First get the Players

Plrs = game.Players:GetChildren()

After that, we are going to select 2 random people out of that, then remove them.

m = math.random(1,#Plrs)
plr1 = m
remove.table[m]
m = math.random(1,#Plrs)
plr2 = m

Then well, there you go! You have 2 people selected randomly! just make sure you Update the Players in the table when you want 2 new players1

2 comments

0

Cool, thanks, this is a very useful method!

0

Np, you can chooes answer too, just so othersk now it's been answered correctly!

This is my answer here that includes a function for keeping the two players from being the same, I included a name finder that may not work but tried not to corrupt the rest of the script with it. Hope this helps.

players = game.Players:GetChildren()
function choose()
p1 = players[math.random(1, #players)]
p2 = players[math.random(1, #players)]
p1name = p1.name -- possible this wont work, try it in studio i guess
p2name = p2.name
end

repeat choose() 
until p1 ~= p2
print(""..p1name.."")
print(""..p2name.."")

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