Hi i need some help

I’m trying to take two from the table Plr
But I don’t want them to be the same plr value form table

local PlayerInGame = game.Workspace.Players.InGamePlayers

local Plr = {}
local Hanters = 0


wait(4)

local function RoundDetails()
	local Players = PlayerInGame:GetChildren()
	Plr = Players	
	
	if #Plr >= 4 then
		Hanters = 2
		local HanterI = Plr[math.random(1,#Plr)]
		
		
	end

end


wait(1)
while wait() do
	RoundDetails()
end
1 Like

Hmm, I guess that didn’t work … Let’s go with simplistic then.

local Players = game.Workspace.Players.InGamePlayers:GetChildren()

if #Players >= 4 then
	local Hunter1Index = math.random(#Players)
	local Hunter2Index
	repeat
		Hunter2Index = math.random(#Players)
	until Hunter2Index ~= Hunter1Index
	local Hunter1, Hunter2 = Players[Hunter1Index], Players[Hunter2Index]
end
1 Like

You could do this by removing players from the Plr table when you select them.

Something like this:

Hanters = 2
local HanterTable = {} --Will contain both selected players

for i = 1, Hanters do
	local HanterId = math.random(1, #Plr)
	table.insert(HanterTable, Plr[HanterId])
	table.remove(Plr, HanterId)
end
2 Likes

its work but wat if i need 3 hunter

use table.remove(Players, math.random(1, #Players)) as many times as you need, table.remove returns the element it removed so you can safely do something like local hanters[1] = table.remove(Players, math.random(1, #Players)) for example

Also is Hanter a typo of Hunter orrr?

In this it is making a table of all the players. It picks one and adds it to a picked table, while also remove them from the player table. Looping for the amount of players you want.

task.wait(3)

local function picks(amount)
	local pickedPlayers = {}
	local players = game:GetService("Players")
	local playerList = players:GetPlayers()

	--local playerList={"me","you","them","us"} --testing
	
	for _ = 1, amount do
		local index = math.random(#playerList)
		table.insert(pickedPlayers, table.remove(playerList, index))
	end	return pickedPlayers
end Hunters=(picks(3))

print(Hunters[1])
print(Hunters[2])
print(Hunters[3])

This is kind of raw by not testing if there is enough players for the pick.
You could add something like this:

totalPlayers = #game:GetService("Players"):GetPlayers()
if totalPlayers > 3 then Hunters=(picks(3)) end