Issue with custom player list

I’m currently trying to make an admin panel with a section that displays all the players names, and updates whenever a player leaves/ joins, I’ve never done anything like this before, it’s not throwing an error or anything and I can’t understand why it won’t work.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	game.ReplicatedStorage.List:FireAllClients(player.Name)
end)

local players = game:GetService("Players")

local repStor = game:GetService("ReplicatedStorage")

local player = game.Players.LocalPlayer

repStor.List.OnClientEvent:Connect(function(playerName)
	wait(2)
	local playerList = player.PlayerGui:WaitForChild("AdminPanel"):WaitForChild("Back"):WaitForChild("PlayerList")
	local UIPositions = {
		0.026, 0,0.027, 0,
		0.026, 0,0.153, 0,
		0.026, 0,0.283, 0,
		0.026, 0,0.412, 0,
		0.026, 0,0.542, 0,
		0.026, 0,0.668, 0,
		0.026, 0,0.785, 0,
		0.026, 0,0.914, 0,
		0.39, 0,0.011, 0,
		0.39, 0,0.136, 0,
		0.39, 0,0.266, 0,
		0.39, 0,0.396, 0,
		0.39, 0,0.525, 0,
		0.39, 0,0.651, 0,
		0.39, 0,0.768, 0,
		0.39, 0,0.898, 0,
		0.763, 0,-0.002, 0,
		0.763, 0,0.124, 0,
		0.763, 0,0.253, 0,
		0.763, 0,0.383, 0,
		0.763, 0,0.513, 0,
		0.763, 0,0.638, 0,
		0.763, 0,0.755, 0,
		0.763, 0,0.885, 0
		}
	
	
	local playerSample = repStor.PlayerSample:Clone()
	playerSample.Parent = player.PlayerGui.AdminPanel.Back.PlayerList
	playerSample.Text = playerName
	playerSample.Position = UDim2.new(UIPositions[#game.Players:GetChildren()])
	playerSample.Visible = true
end)

Can you share the error you are receiving?

Also, you do not need a RemoteEvent for this; instead, you can listen to PlayerAdded on the client. Additionally, you do not have to keep an array of positions for your UI; instead, you can use a UIListLayout to do it for you.

1 Like

Hey, thanks for the response, I’m not getting an error for some reason.

It is due to the way you are positioning your elements most likely. Try removing the UIPositions array and the line that sets the element’s position, and allow a UIListLayout to take care of placing the objects for you.

2 Likes