Custom Player List Script Not Working

So I recently followed a tutorial to experience with making a custom player list gui, but it doesn’t seem to work, I don’t really remember from who I took the tutorial I am sorry for that but here is the code.

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local Item = game.ReplicatedStorage:WaitForChild("Item")
local Holder = script.Parent:WaitForChild("Holder")

local function add(Player)
	local New = Item:Clone()
	New.Name = Player.Name
	New.Name.Text = Player.Name
	if not New.Name.TextFits then
		New.Name.TextScaled = true
	end
	New.Position = UDim2.new(.87, 0, .01 + (.05 * #Holder:GetChildren()), 0)
	New.Parent = Holder
end

for i,v in pairs(game.Players:GetPlayers()) do
	add(v)
end

game.Players.PlayerAdded:Connect(function(Player)
	add(Player)
end)

game.Players.PlayerRemoving:connect(function(Player)
	local find = Holder:FindFirstChild(Player.Name)
	if find then
		find:Destroy()
		for i,v in pairs(game.Players:GetPlayers()) do
			v.Position = UDim2.new(.87, 0, .01 + (.05 * #Holder:GetChildren()), 0)
		end
	end
end)

And the error:
image

2 Likes

The issue here is you have a TextLabel named Name. Class members (properties, events, methods) have higher precedence over children, so you’re getting the Name property and not a child.

So rename it to something like PlayerName and it will work.

4 Likes

Okay so I have changed the name of the TextLabel inside the Frame but it still says a error in the output, here are the changed code, workspace and the error and thanks for pointing out one of the problems!

Code:

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local Item = game.ReplicatedStorage:WaitForChild("Item")
local Holder = script.Parent:WaitForChild("Holder")

local function add(Player)
	local New = Item:Clone()
	New.pName = Player.Name
	New.pName.Text = Player.Name
	if not New.pName.TextFits then
		New.pName.TextScaled = true
	end
	New.Position = UDim2.new(.87, 0, .01 + (.05 * #Holder:GetChildren()), 0)
	New.Parent = Holder
end

for i,v in pairs(game.Players:GetPlayers()) do
	add(v)
end

game.Players.PlayerAdded:Connect(function(Player)
	add(Player)
end)

game.Players.PlayerRemoving:connect(function(Player)
	local find = Holder:FindFirstChild(Player.Name)
	if find then
		find:Destroy()
		for i,v in pairs(game.Players:GetPlayers()) do
			v.Position = UDim2.new(.87, 0, .01 + (.05 * #Holder:GetChildren()), 0)
		end
	end
end)

Workspace:

Error:
image

cc: @incapaz


2 Likes

If you are trying to set pName as player name than it should be

New.pName.Name = Player.Name
3 Likes