My custom playerlist duplicates an existing player when updated

My Custom Player List is duplicating an existing player when it updates or when I search the name


function updatePlayers2()


	for i, child in pairs(scroller2:GetChildren()) do

		if child:IsA("ImageLabel") then child:Destroy() end
	end


	for i, plr in pairs(game.Players:GetPlayers()) do


		local img = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)


		local templateClone = template2:Clone()
		templateClone.RealName.Text = plr.Name
		templateClone.Rank.Text = plr:GetRoleInGroup(CanariaModule.GroupID)
		templateClone.Face.Image = img


		templateClone.Parent = scroller2


		scroller.CanvasSize = UDim2.new(0, 0, 0, scroller.UIListLayout.AbsoluteContentSize.Y)
	end
end


updatePlayers2()
game.Players.PlayerAdded:Connect(updatePlayers2)
game.Players.PlayerRemoving:Connect(updatePlayers2)



``
Thank you!

Maybe it is duplicating because you are using two update functions…?
Also it seems like your “templateClone” isn’t a imageLabel

I am using two update functions but the other one has a different name

This is the script:


function updatePlayers()


	for i, child in pairs(scroller:GetChildren()) do

		if child:IsA("ImageLabel") then child:Destroy() end
	end


	for i, plr in pairs(game.Players:GetPlayers()) do


		local img = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

		if not scroller:FindFirstChild(plr.Name) then
			local templateClone = template:Clone()
			templateClone.RealName.Text = plr.Name
			templateClone.Rank.Text = plr:GetRoleInGroup(CanariaModule.GroupID)
			templateClone.Face.Image = img


			templateClone.Parent = scroller


			scroller.CanvasSize = UDim2.new(0, 0, 0, scroller.UIListLayout.AbsoluteContentSize.Y)
		end

	end
end

updatePlayers()
game.Players.PlayerAdded:Connect(updatePlayers)
game.Players.PlayerRemoving:Connect(updatePlayers)

I believe templateClone is an ImageLabel

image

I don’t know if this is an ImageLabel or ImageButton

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