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)
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.