Progress Bar glitching out sometimes

Hello! Today, I wanted to create a progress bar UI for my math game. However, my client script sometimes behaves strangely.

Code:

ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("UpdatePlayerCountTeleport").OnClientEvent:Connect(function(TABLE)
    
    Functions.UpdatePlayerCount(TABLE)
    
    local ProgressFrame = player.PlayerGui:WaitForChild("MainGui"):WaitForChild("ProgressFrame")
    local PlayersFrame = ProgressFrame.Players
    
    local Colors = {
        Color3.new(0.313725, 1, 0.588235),
        Color3.new(1, 1, 0.294118),
        Color3.new(1, 0.52549, 0.184314),
        Color3.new(0.309804, 0.666667, 1),
        Color3.new(1, 0.32549, 0.337255),
        Color3.new(0.976471, 0.294118, 1),
    }
    
    for _, information in pairs(TABLE) do
        
        --[[
        
        information[1] = stage value
        information[2] = difficulty string
        information[3] = player
        
        ]]
        
        if not PlayersFrame:FindFirstChild(information[3].Name) then
            
            local content, isReady = game.Players:GetUserThumbnailAsync(tonumber(information[3].UserId), Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
            
            local CLONE = script:WaitForChild("PlayerFrame"):Clone()
            CLONE.Name = information[3].Name
            CLONE.Frame.ImageLabel.Image = content
            CLONE.Frame.UIStroke.Color = Colors[math.random(1, #Colors)]
            CLONE.Parent = PlayersFrame
            CLONE:TweenPosition(UDim2.new(information[1] / 61 * 0.94, 0, -2.7, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.08, false)
            
            if player.Name == information[3].Name then
                CLONE.Frame.Title.Visible = true
            end
            
        elseif PlayersFrame:FindFirstChild(information[3].Name) then
            PlayersFrame:FindFirstChild(information[3].Name):TweenPosition(UDim2.new(information[1] / 61 * 0.94, 0, -2.7, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.1, false)
        end
        
        --Clean Up if someone left--
        
        for _, frame in pairs(PlayersFrame:GetChildren()) do
            if frame:IsA("Frame") then
                if not game:GetService("Players"):FindFirstChild(frame.Name) then
                    frame:Destroy()
                end    
            end
        end
    end
end)

Here are some screenshots showing the issue.

image image

Any help is very appreciated! :smile:

Wait, so whats the issue you are experiencing?

As you can see there is a few clones of me in the screenshot, when there should be only one.

Try changing the line
if not PlayersFrame:FindFirstChild(information[3].Name) then
to
if PlayersFrame:FindFirstChild(information[3].Name) == nil then

Fixed the bug by adding spawn.task() and debounce.

1 Like

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