Basically I am running a script where it will randomly select two players who will compete against each other. Once those two players are chosen, a boolean value inside their player will be made true, showing they've already played. On the next competition, how would I make sure that the players who already competed do not compete again?
game.Players.PlayerAdded:connect(function(plr) local a = Instance.new("BoolValue",plr) a.Name = "HasGoneThisRound" a.Value = false end)
You don't need to create a new object for every player and physically store it inside of the game. You can do all of this in the script.
local competed={} function ChooseTwo() local available={} for _,v in pairs(game.Players:GetPlayers())do if not competed[v]then available[#available+1]=v end end if #available<2 then return end local first=table.remove(available,math.random(#available)) local second=available[math.random(#available)] competed[first]=true competed[second]=true return first,second end
Store all of the players who have competed in a table, list all of the players who are not in that table, choose two randomly. The function will return nothing if there are not two players left to choose from, otherwise it returns the two players and adds them to the table.