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)
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.
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)
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.
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)