Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Having the same Player list in a local script for all of the players?

i have a local script where i need the list of players in a table... if i use game.Players.PlayerAdded and table.insert or GetPlayers() it always puts the LocalPlayer in the first place in the table, which is not what i want because let's say i have 2 clients, one joins and gets the first place in the table but then the second joins too but he gets the first place in the table too but only the client sees it... i need both clients to have the same exact table so i used remote function which i'm forced to use in a Heartbeat because of what i said above but remote functions make my local script wait till the global script returns a value/finishes and it's in my camera script which makes the camera choppy.

any help please??

1 answer

Pretty sure this would work, not tested it with multiple players.

local tableA={}
local tableB={}

for i,v in pairs(game.Players:GetChildren()) do
	table.insert(tableA,v.Name)
end
local num=0
repeat
	local rng=math.random(1,#game.Players:GetChildren())
	for i,v in pairs(tableA) do
		if i==rng then
			table.insert(tableB,v)
			table.remove(tableA,i)
		end
	end
	num=num+1
until num == #game.Players:GetChildren()

If this helped, please accept my answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.