Problem with custom player list

hello! i made this custom clickable player list earlier and it works well until another player leaves.

when the player joins it adds their name, etc and its destroyed when they leave. however if ANOTHER player leaves then it makes a duplicate of my own player slot like so:
image

does anyone know how to fix this?

script:

local template = script.Parent.plrScroll.plrName
local plrs = game:GetService("Players")

function updPlrs()

	local plr = game.Players.LocalPlayer
	local thumbnailtype = Enum.ThumbnailType.HeadShot
	local thumbnailsize = Enum.ThumbnailSize.Size420x420

for i, p in pairs(game.Players:GetPlayers()) do
		local thumbnail = plrs:GetUserThumbnailAsync(p.UserId, thumbnailtype, thumbnailsize)

	local templateClone = template:Clone()

templateClone.Name = p.Name
	templateClone.Parent = script.Parent.plrScroll
	templateClone.Visible = true
		templateClone.Text = p.Name
		templateClone.displayName.Text = "@"..p.DisplayName
		templateClone.PFP.Image = thumbnail

end
end

function removeSlot(plr)
	for i, child in pairs(script.Parent.plrScroll:GetChildren()) do
		if child.Name == plr.Name then
			child:Destroy()
		end
	end
end

updPlrs()
game.Players.PlayerAdded:Connect(updPlrs)
game.Players.PlayerRemoving:Connect(removeSlot)
1 Like

The two events you’re using PlayerAdded and PlayerRemoving aren’t really made for client-sides use, I would suggest using remote events and sending that information to the client.

2 Likes

this is missing an argument I think

No, you CAN connect events to already made functions.

@EnvisionDev That’s not what he meant. He said missing an argument, not that events can’t be connected to already made functions. However, it’s not missing an argument, so that’s not the OPs problem.

1 Like

forgot ab that tbh. i changed it to a script. ty 4 that!

1 Like

to give more context the player who is already in the game is getting duplicates of their slot twice (bc 2 players i assume) and duplicates of the other plrs.

whereas the newly joined plrs look like this:

Its kind of hard to explain why its not working, but you are creating to many player listings. I would instead change your updPlrs() function to look like this.

function updPlrs()

	local plr = game.Players.LocalPlayer
	local thumbnailtype = Enum.ThumbnailType.HeadShot
	local thumbnailsize = Enum.ThumbnailSize.Size420x420

	for i, p in pairs(game.Players:GetPlayers()) do
		
		if (script.Parent.plrScroll:FindFirstChild(p.Name)) then continue end
		
		local thumbnail = plrs:GetUserThumbnailAsync(p.UserId, thumbnailtype, thumbnailsize)

		local templateClone = template:Clone()

		templateClone.Name = p.Name
		templateClone.Parent = script.Parent.plrScroll
		templateClone.Visible = true
		templateClone.Text = p.Name
		templateClone.displayName.Text = "@"..p.DisplayName
		templateClone.PFP.Image = thumbnail

	end
	
end
1 Like

when using updPlrs you forgot to check if the leaderboard label already existed for the player.

So player A joins, gets label for themselves, then player B joins, and player A gets a label for player B and another for themselves

2 Likes

THIS! I couldn’t figure out how to explain it but I wrote fix script above to function that way! :rofl:

1 Like

UGH, i had if script.Parent.plrScroll:FindFirstChild(p.Name) then continue end earlier. i didnt put in the extra brackets for the
lua (script.Parent.plrScroll:FindFirstChild(p.Name)) part

what does the extra brackets do if u dont mind me asking? thank u so so much for ur help chloe! i really appreciate it :slight_smile:

1 Like

yes u were so right. thank u for ur help!

1 Like

The extra brackets help out roblox a little bit, and for me just help organize, they aren’t usually necessary but it has helped me before! If you put something in brackets, roblox recognizes it first if that makes sense, like math!

(3 + 3) / 2 → “3”
3 + 3 / 2 → “4.5”

1 Like

OHHHH right. i get it now. chlo thank u so much have a great day :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.