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

Creating Biased Random With Given Code?

I have a game that randomly selects 2 people. The thing that's making players mad is that some people go more than others. How would I go on implementing a script to make it so that the last 2 people that have played don't go again for the next couple of games?

local Players = game.Players:GetPlayers() 
math.randomseed(tick()) 
local Chosen1, Chosen2 = math.random(1, #Players) 
repeat wait() 
    math.randomseed(tick()) 
    Chosen2 = math.random(1, #Players) 
until Chosen2 ~= Chosen1 
local P1 = Players[Chosen1] 
local P2 = Players[Chosen2] 
print(P1.Name) 
print(P2.Name)

1 comment

1

Insert the last two players into a table and check that the chosen players are not in the table , and them remove them from the table when you want them to be able to play again.

1 answer

✓ Accepted answer

Try this:

math.randomseed(tick())
local Players = game:GetService('Players')

local Chosen = {}

local function ChooseRandomPlayers()
	local R1, R2 = math.random(1, #Players:GetChildren())
	return R1, R2
end)

repeat wait()
local R1, R2 = ChooseRandomPlayers()
until not Chosen[Players[R1]] and not Chosen[Players[R2]] do end
Chosen[Players[R1]] = true
Chosen[Players[R2]] = true

This is a really rough code. But it has the basic table elements down. What you can do is reset all the players to false after everyone has gone once. to reset it. Hopefully this helped. Another thing you can do is store the number of times the player has been chosen and then compare for the smallest values.

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