Need help making script select 3 random players and giving each a unique tool

The script I have below selects a random player and gives them a tool, how would I edit this to make it select 3 players instead and each of the chosen players will receive a different weapon? Any help is appreciated ^^

local Players = game.Players:GetPlayers()
local nplrs = #Players
local Randomplayer = nil


if nplrs > 0 then
	Randomplayer = Players[math.random(1, nplrs)]
end


print(Randomplayer)


game.ServerStorage["ToolHere"]:Clone().Parent = Randomplayer:WaitForChild("Backpack")
1 Like

Not sure if this works:

local SelectedPlayers = {}
local MAX_WAIT = 30

local StartTime = os.clock()

while #SelectedPlayers < 3 do
	-- Incase the loop got stuck and can't find other players
	if (os.clock() - StartTime) >= MAX_WAIT then
		break
	end

	local RandomPlayer = Players[math.random(1, #Players)]

	-- Checks if the random player already exist on the table
	if not table.find(SelectedPlayer, RandomPlayer) then
		table.insert(SelectedPlayer, RandomPlayer)
	end
end
1 Like

make use of a for loop. add a check to prevent previously selected players from being re-selected. give a weapon based on what number of loops have been made

1 Like

You can make a variable for how many players you’ve collected, then add all of them to a table and cycle through them and clone the tool in each of their backpacks.

1 Like