[SOLVED] Queue system Duplicates twice?

I have an issue with my queue system
Video below will show what the issue is

Local script:

local frame = script.Parent.Frame
local template = frame.Template
local scroll = frame.ScrollingFrame
local join = frame.Join
local leave = frame.leave
local button = script.Parent.Button
local remote = game.ReplicatedStorage.Queue
local player = game.Players.LocalPlayer


remote.OnClientEvent:Connect(function(table, plr, func)
	print(table)
	print(table[1])
	print(plr.Name)
if string.lower(func) == "join" then
	for index, value in table do
		local userId = player.UserId
		local thumbType = Enum.ThumbnailType.HeadShot
		local thumbSize = Enum.ThumbnailSize.Size420x420
		local content, isReady = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
		print(index, value)
		--[[
		local thing2 = Instance.new("Frame")
		thing2.Visible = true
		thing2.BackgroundTransparency = 1
		thing2.Size = UDim2.new(1, 1, 1, 1)
		thing2.Name = plr.Name
		thing2.Parent = scroll
		]]
			local thing = template:Clone()
			thing.Username.Text = plr.Name
			thing.placement.Text = index
			thing.Rank.Text = plr:GetRoleInGroup(17100957)
			thing.Parent = scroll
			thing.Visible = true
			thing.Name = plr.Name
			thing.UserImage.Image = content
			game["Run Service"].Heartbeat:Connect(function()
				if not scroll:FindFirstChild(plr.Name) then
					return
				else
					if #scroll:FindFirstChild(plr.Name):GetChildren() > 1 then
					--thing2:Destroy()
					--remote:FireServer("leave")
				end
				end
				
			end)
	end
end
	if string.lower(func) == "leave" then
		if not scroll:FindFirstChild(plr.Name) then
			return
		else
			local thing = scroll:FindFirstChild(plr.Name)
			thing:Destroy()
		end
			
			
		
	end
	if string.lower(func) == "leaveplrqueue" then
		
	end
end)




player:GetPropertyChangedSignal("Team") :Connect(function()

	if not scroll:FindFirstChild(player.Name) then
		return
	else
		local thing = scroll:FindFirstChild(player.Name)
		thing:Destroy()
		leave.Visible = false
		join.Visible = true
	end		
end)

button.MouseButton1Click:Connect(function()
	frame.Visible = not frame.Visible
end)

join.MouseButton1Click:Connect(function()
	remote:FireServer("join")
	join.Visible = false
	leave.Visible = true
end)

leave.MouseButton1Click:Connect(function()
	local thing = game.HttpService:JSONDecode(game.StarterGui.QueueTable.Value)
	remote:FireServer("leave")
	leave.Visible = false
	join.Visible = true
end)

Server script

local remote = game.ReplicatedStorage.Queue

local tablePlayer = {
	
}

remote.OnServerEvent:Connect(function(plr, text, func)
	print(text)
	if string.lower(text) == "join" then
		table.insert(tablePlayer, plr.Name)
		print(tablePlayer[1])
		remote:FireAllClients(tablePlayer, plr, "join")
	end
	if string.lower(text) == "leave" then
		
		remote:FireAllClients(tablePlayer, plr, "leave")
		--table.remove(tablePlayer, plr.Name)
		print(tablePlayer[1])
		for i, player in tablePlayer do
			table.remove(tablePlayer, i)
			print(tablePlayer[1])
			remote:FireAllClients(tablePlayer,plr,"leaveplrqueue")
		end
	end
end)

game["Run Service"].Heartbeat:Connect(function()
	game.StarterGui.QueueTable.Value = game.HttpService:JSONEncode(tablePlayer)
end)

Can you send a screenshot of Output?

yep give me a second, sorry for long response

1 Like

image

Server then client
image

No errors

(I will be going to sleep now, won’t respond until morning)

I believe the problem come the client script.

When you send a “join” request to the server, the server adds that player’s name to a table and then sends that table back to the clients. On the client, there will be one duplicate of the template for every player inside that table. The reason why there are two frames when Player2 joins the queue is because there are two players in the table when you send it the second time, so it clones the template twice.

To fix this, I would delete all children of frame.ScrollingFrame and then generate a template for each player in the table.

This actually helped- Thanks! Char limit

1 Like

Glad I could help you :slight_smile: (Would appreciate it if you could mark it as the Solution)

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