I am making a game where two random players are picked and compete. Here is my script:
game.Players.PlayerAdded:connect(function(plyr)
local chosen=Instance.new("StringValue",plyr)
chosen.Name=("chosen")
chosen.Value=("Zero")
end)
local model=game.Players
player = model:GetChildren()[math.random(#model:GetChildren())]
if player.chosen.Value==("Zero") then
player.chosen.Value=("One")
end
player = model:GetChildren()[math.random(#model:GetChildren())]
if player.chosen.Value==("Zero") then
player.chosen.Value=("Two")
end
This script looks inefficient and most times it does not work for me. Is there a better way to pick random players?

3 comments
Unless you have more code somewhere, the script will run before anyone joins the game. Also, you should allow for if the same player is picked twice - don't want that.
Are there any errors? Also why are you using a string value? An IntValue will work with 0,1 and 2
What I'm asking for here is a way to not allow the same player to be picked twice