How can i get rid of duplicates?

What can i do to get rid of duplicates with the same name such as these:
image

Local script Code:

local players = {}
local frames = {}
local newValue --6436346
local isfinished = false
game.ReplicatedStorage.GetQueue.OnClientEvent:Connect(function(requests, currentid, targetusername, isrunning)
	for _,v in pairs(requests) do
		isfinished = false
		print(requests)
		table.insert(players, v)
		print("v = "..v)
		print(players)
		local clone = game.ReplicatedStorage.QueueExample:Clone()

		clone.Name = v
		newValue = v
		clone.Username.Text = targetusername
		clone.Parent = script.Parent.Frame.Frame.Folder
		print(players)
		--======MAIN=======
		for index,value in pairs(players) do
			--if isfinished == false then
			print("Value : "..value)
			print("here!")
			print(players[table.find(players, value)], newValue) --if players.23422344
			if players[table.find(players, value)] ~=  newValue then --if player[old id] ~= v(NEW ID) then
				print("NO!")
				print(players)
				print(players[table.find(requests, players)], "old: "..value) ---VALUE NOT UPDATING. CAUSING ERROR WHEN CALLED MORE THAN 2 TIMES
				print(#players)
				script.Parent.Frame.Frame.Folder:FindFirstChild(players[table.find(players, value)]):Destroy() --centre of errors "Argument 1 missing or nil"
				print(players[index])

				print(players, value)
				--	isfinished = true
				print("set to nil")
				table.remove(players, index)
				--players[index] = nil
				print(players)

			else
			end
		end
		--======MAIN======================
		
	
	end
end)

Server script code:

local httpService = game:GetService("HttpService")
local baseUrl1 = "https://avatar.roblox.com/v1/users/"
local baseUrl2 = "/outfits?itemsPerPage=50"
local requests = {}
local proxyHttp = require(game.ServerScriptService.ProxyRobloxAPI:Clone())
local v
local targetUserId
local targetUserName
local isRunning = false
local isSendingServer = false
local currentid
local outfitFrame


local function checkPlayer()

	if isRunning == false then
		print("Running Properly")
		isRunning = true
		isSendingServer = true

		if #requests >= 1 then


			local userId = (requests[1])

			local s, x = pcall(function()
				local data = proxyHttp:GetAsync(baseUrl1..userId..baseUrl2) -- https://avatar.roblox.com/v1/users/2046139136/outfits?itemsPerPage=50
				if data then

					print("cleared")
					game.Workspace.Map.Outfits:ClearAllChildren()
					local outfits = data.data 
					for i, v in pairs(outfits) do
						currentid = requests[1]
						local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
						local thumb = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

						workspace.UserImage.SurfaceGui.ImageLabel.Image = thumb
						local c = game.ServerStorage.BaseAvatar:Clone()
						c.Name = v.name
						c.Parent = workspace.Map.Outfits
						c.HumanoidRootPart.Position = Vector3.new(-123 + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), -5, -59.5)
						c.Humanoid.NameDisplayDistance = 50
						c.Humanoid:ApplyDescription(desc)
						c.HitBox.Position = c.HumanoidRootPart.Position

					end
				end
				table.remove(requests, table.find(requests, currentid))
				game.ReplicatedStorage.GetQueue:FireAllClients(requests, currentid, targetUserName, isRunning)
				print("table removed")
				wait(1)
				isRunning = false
				isSendingServer =false
				
			end)
		end



	end
end

local loop = function()
	while true do
		wait(3)
		
		if #requests == 1 then
			checkPlayer()
			
			
		else
			repeat game:GetService("RunService").Heartbeat:Wait() until #requests >= 1
		end
	end
end



game.ReplicatedStorage.RequestUser.OnServerInvoke = function(plr, targetName) -----FIRST THING IN THIS SCRIPT TO HAPPEN
	local s, x = pcall(function()
		targetUserName = targetName
		
		targetUserId = game.Players:GetUserIdFromNameAsync(targetName) --get name id
		workspace.UserImage.SurfaceGui.Enabled = true
		table.insert(requests, targetUserId)
		
		game.ReplicatedStorage.GetQueue:FireAllClients(requests, currentid, targetUserName, isRunning)
		
		
		if isRunning == false then
			if #requests == 1 then
				wait()
				checkPlayer()
				print("Put in queue")
				
			end
		end
		
		
	end)
	if not s and x then warn(x) end
end

coroutine.wrap(loop)()

image

7 Likes

what is causing the duplicates ?

Not quite sure, the duplicates happen when the remote event at the top activates this localscript while there is something in the queue system. ill edit the post with the code.

You need to check if there is a frame with the same info already there