Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

2 comments

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

0

What line is the error on?

1 answer

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! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.