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:
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)
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.
@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.
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.
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
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
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!