So I want to make a script that makes the game pick 1+ player randomly and is not the same person the game chose before.
Make a list of all the players and randomly pick. After picking a player, remove them from the list
local PlayerList = {} local function refresh() PlayerList = {} for _, plr in pairs(game.Players:GetChildren()) do --for every child (player) of the game.Players table.insert(PlayerList, plr.Name) --add the player's name to the list end end local function RandomPlayer() local num = math.random(1, #PlayerList) --get a random index number local player = PlayerList[num] --Get player with that index number for index, plr in pairs(PlayerList) do --Go through every player in the list if plr == player then --When the player is found... table.remove(PlayerList, index) --remove them from the list and... return game.Players[player] --return the player's instance end end end
Here are the functions you need
To randomly pick a player, do:
local Players = game:GetService('Players') local playerList = Players:GetPlayers() local randomPlayer = playerList[math.random(1, #playerList)]
To make it not pick the previous player, store the previous player as a variable and compare it with the new player:
local Players = game:GetService('Players') local previousPlayer repeat local playerList = Players:GetPlayers() local randomPlayer = playerList[math.random(1, #playerList)] until (previousPlayer ~= randomPlayer) previousPlayer = randomPlayer