I’m having a problem where each player gets several labels each. How can I get it to only create 1 for each player
-- Create the Player label
local function CreateLabel(player)
-- Create a label for this player
local PlayerLabel = PlayerTemplate:Clone()
PlayerLabel.Name = player.Name
PlayerLabel.Icon.Image = Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
PlayerLabel.Parent = PlayerList
return PlayerLabel
end
-- Update the PlayerLabel positions
local function Update()
if TotalSize <= 0 then return end
for _, player in pairs(Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild('HumanoidRootPart') then
local PlayerLabel = PlayerList:FindFirstChild(player.Name)
if not PlayerLabel then
-- Create label
PlayerLabel = CreateLabel(player)
end
-- Calculate players distance
local Distance = player.Character.HumanoidRootPart.Position.Y - Start.Floor.Position.Y - 2
-- Set position
PlayerLabel.Position = UDim2.new(0, 0, 1 - (Distance / TotalSize), 0)
if Highest > Distance then return end
Highest = Distance
-- Set player's highest progress
local ProgressLine = Frame:FindFirstChild('Progress')
if not ProgressLine then return end
ProgressLine.Visible = true
-- Set progress line position
ProgressLine.Position = UDim2.new(0, 0, 1 - (Highest / TotalSize), 0)
end
end
end
RunService.Heartbeat:Connect(Update)