So I have this simple queue display that will display players currently in the queue before they’re teleported into the game. My issue is that when I walk onto the platform multiple of a player’s name will show up. I’ve tried moving where the update display functions go but I’m not sure where it’s going wrong.
Here’s the code:
local Template = game.ReplicatedStorage.QueueTemplate
local Gui = script.Parent.Board.SurfaceGui
local Queue = {}
local QueueOpen = true
local Players = game:GetService("Players")
local function UpdateDisplay()
for i, object in pairs(Gui:GetChildren()) do
if object:IsA("Frame") then
object:Destroy()
end
end
for i = 1, #Queue do
local Clone = Template:Clone()
Clone.PlayerLabel.Text = Queue[i]
local UserId = 0
local ThumbType = Enum.ThumbnailType.HeadShot
local ThumbSize = Enum.ThumbnailSize.Size100x100
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Name == Queue[i] then
UserId = player.UserId
end
end
local content, isReady = Players:GetUserThumbnailAsync(UserId, ThumbType, ThumbSize)
Clone.PlayerImage.Image = content
Clone.Parent = Gui
end
end
game.ReplicatedStorage.QueueClose.Event:Connect(function()
QueueOpen = false
end)
game.ReplicatedStorage.QueueOpen.Event:Connect(function()
QueueOpen = true
end)
script.Parent.QueuePart.Touched:Connect(function(plr)
local Human = plr.Parent:FindFirstChild("HumanoidRootPart")
if Human and QueueOpen == true then
local Duplicate = false
for i = 1, #Queue do
if Queue[i] == plr.Parent.Name then
Duplicate = true
end
end
if Duplicate == false then
table.insert(Queue, plr.Parent.Name)
end
end
UpdateDisplay()
end)
script.Parent.ExitQueue.Touched:Connect(function(plr)
local Human = plr.Parent:FindFirstChild("HumanoidRootPart")
if Human and QueueOpen == true then
for i = 1, #Queue do
if plr.Parent.Name == Queue[i] then
table.remove(Queue, i)
end
end
end
UpdateDisplay()
end)
game.Players.PlayerRemoving:Connect(function(plr)
for i = 1, #Queue do
if plr.Name == Queue[i] then
table.remove(Queue, i)
end
end
UpdateDisplay()
end)
UpdateDisplay()