Custom player list not working

here is my code for my custom player list, it doesn’t seem to work for me.
CustomPlayerList.rbxl (21.2 KB)

can someone please review it and tell me what is wrong?
(i used roundify to make the gui have a rounded edge, i don’t know if that effected it)

1 Like

I would recommend doing

for _,v in pairs(holder:GetChildren()) do
	v:Destroy()
end
for i,plr in pairs(game.Players:GetChildren()) do
	local item1 = item:Clone()
	item1.TextLabel.Position = UDim2.new({0, 0},{0, 30*i})
	item1.TextLabel.Text = plr.Name --You should change "Name"'s name to something else
	item1.Parent = holder
end
game.Players.PlayerAdded:Connect(function()
	for _,v in pairs(holder:GetChildren()) do
        v:Destroy()
    end
    for i,plr in pairs(game.Players:GetChildren()) do
        local item1 = item:Clone()
		item1.TextLabel.Position = UDim2.new({0, 0},{0, 30*i})
        item1.TextLabel.Text = plr.Name --You should change "Name"'s name to something else
		item1.Parent = holder
    end
end)
game.Players.PlayerRemoving:Connect(function()
	for _,v in pairs(holder:GetChildren()) do
        v:Destroy()
    end
    for i,plr in pairs(game.Players:GetChildren()) do
        local item1 = item:Clone()
		item1.TextLabel.Position = UDim2.new({0, 0},{0, 30*i})
        item1.TextLabel.Text = plr.Name --You should change "Name"'s name to something else
		item1.Parent = holder
    end
end)

so do i change the name of item to item1 and what should i change name to?

Doesn’t really matter. Whatever you change it to, change any “TextLabel” to the name that you picked. You should never name anything “Name”, as when you try and define it it will think that you are talking about its parent’s name instead of the instance named “Name.”
You should click the “Reply” button underneath the post you are replying to, don’t reply to the original post if you are replying to a reply to the original.

do i replace all the code (apart from the code up to line 4) or replace the code at line 17

Replace all the code except for the first 2(?) lines. Replace any functions with my code.

line 2 is empty, do i still replace the 3rd?

Just delete the functions and replace them with my code.

your code is repeated twice, is that supposed to happen?

Whatever I wrote is intended. You can figure it out on your own you won’t learn if I tell you every little step.


is this how it is supposed to be?

Here are my recommendations:

  1. Use a UIListLayout. They will save you the hassle of positioning the items themselves, and they can sort players alphabetically (given that you set the name of ImageLabel to the player’s name)

  2. Put your code into one function instead of copying the code 3 times. This makes it easier to modify your code if you need to later.

  3. I don’t see where holder is defined in your script. At the top, you should have local holder = script.Parent:WaitForChild("holder") so that your script knows what exactly holder is.

Code:

local holder = script.Parent:WaitForChild("holder")

function UpdatePlayers()
	for _,v in pairs(holder:GetChildren()) do
        if v:IsA("TextLabel") then -- If using UIListLayout, don't remove it.
            v:Destroy()
        end
    end
    for i,plr in pairs(game.Players:GetPlayers()) do
        local item1 = item:Clone()
        item1.TextLabel.Text = plr.Name
        item1.Name = plr.Name -- Used for sorting with UIListLayout
		item1.Parent = holder
    end
end

UpdatePlayers()
game.Players.PlayerAdded:Connect(UpdatePlayers)
game.Players.PlayerRemoving:Connect(UpdatePlayers)
1 Like

for the ui layout, do i put it in the same script and above all the other code?

and do i use this:
(javascript:void(0))local uiListLayout = Instance.new(“UIListLayout”)
uiListLayout.SortOrder = Enum.SortOrder.Layout
uiListLayout.FillDirection = Enum.FillDirection.Horizontal
uiListLayout.HorizontalAlignment = Enum.HorizontalAlignment.Right
uiListLayout.Parent = item

Why are you creating it with a script? Right click on the frame itself in the explorer and insert one in. Change its properties that way.