Scripting Support Needed

Hello! I asked ChatGPT how to make a part that shows someone with the highest time in the games profile picture on it. (Like their face on roblox) I’m not sure what to do with what he gave me. so far i have a part and a surface gui on it with an image label.

heres the code he gave me:

-- Find the player with the highest time
local function getPlayerWithHighestTime()
    local highestTime = 0
    local highestPlayer = nil
    for _, player in ipairs(game.Players:GetPlayers()) do
        local leaderstats = player:FindFirstChild("leaderstats")
        if leaderstats then
            local timeStat = leaderstats:FindFirstChild("Time")
            if timeStat and timeStat.Value > highestTime then
                highestTime = timeStat.Value
                highestPlayer = player
            end
        end
    end
    return highestPlayer
end

-- Create a SurfaceGui on the desired part
local part = -- Reference to the part you want to attach the SurfaceGui to
local surfaceGui = Instance.new("SurfaceGui")
surfaceGui.Parent = part
surfaceGui.Face = Enum.NormalId.Front -- Adjust this based on the face of the part you want to attach it to
surfaceGui.CanvasSize = Vector2.new(100, 100) -- Adjust as needed

-- Add an ImageLabel to display the avatar
local playerWithHighestTime = getPlayerWithHighestTime()
if playerWithHighestTime then
    local avatarImage = Instance.new("ImageLabel")
    avatarImage.Parent = surfaceGui
    avatarImage.Size = UDim2.new(1, 0, 1, 0)
    avatarImage.BackgroundTransparency = 1
    -- Get the player's avatar URL
    local avatarUrl = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. tostring(playerWithHighestTime.UserId) .. "&width=420&height=420&format=png"
    avatarImage.Image = avatarUrl
end

im confused. THANKS

Sometimes AI creates scripts that don’t even work, you need to have scripting experience to understand where errors are. first you need somewhere in your script that adds time to the player.

1 Like

yes, you were right. i misread his instructions. he specifically said “implement this into your script” thank you for your help. i hope it works now haha

1 Like

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