Ad
Log in to vote
0

How to put an avatar thumbnail on an GUI when a UserID is typed?

Asked by 3 days ago

Hey there, I'm currently making a system so when the player types a UserID it displays the thumbnail of that user's character but I'm getting the error "Argument 1 missing or nil"

This is the code that I'm using:

local text = script.Parent.Text
local Players = game:GetService("Players")

local function update(id)
    local userId = tonumber(id)
    local thumbType = Enum.ThumbnailType.AvatarThumbnail
    local thumbSize = Enum.ThumbnailSize.Size420x420
    local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)


    local imageLabel = script.Parent.Parent.avatar
    imageLabel.Image = content
end

script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
    update(text)
end)

Help would be appreciated :D

0
your 'text' variable is set to the text on start and never updates, you can try moving it above the update(text) line. you will still get that error when you dont have a valid user id though enzotinman1 22 — 3d
0
What line is the error on? MarTieMak 39 — 3d

1 answer

Log in to vote
0
Answered by 2 days ago

Hey there! Try this.

local Players = game:GetService("Players")

local function Update(UserId)
    if Players:GetNameFromUserIdAsync(UserId) then
        local ThumbnailType = Enum.ThumbnailType.AvatarThumbnail
        local ThumbnailSize = Enum.ThumbnailSize.Size420x420

        local Content = Players:GetUserThumbnailAsync(
            UserId,
            ThumbnailType,
            ThumbnailSize
        )

        if Content then
            script.Parent.Parent:WaitForChild("avatar").Image = Content
        end
    end
end

script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
    Update(script.Parent.Text)
end)

G'day! :)

Ad

Answer this question