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

Is there anyway to change a failed images picture to that of something that will load?

I have a simple script that shows your characters face on a GUI. But the thing when you change your character it loads with NA makes it look goofy, is there any way that if it doesn't load it can change it to some random player of my choosing s character?

7 comments

0

Are you getting it from their profile pic?

0

Yes

0

Can you post the code?

0

local Players = game:GetService("Players") local player = Players.LocalPlayer -- Fetch the thumbnail local userId = player.UserId local thumbType = Enum.ThumbnailType.AvatarBust local thumbSize = Enum.ThumbnailSize.Size352x352 script.Parent.Image = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

0

Do you know what it says the AssetID is when it fails?

0

Don't you dare try to use an if statement....

0

The asset is the same,from what I notice

1 answer

The function to grab their icon has a built-in failure detector. You can use that to check if the icon hasn't loaded and change the image to a default instead.

The function GetUserThumbnailAsync() returns the image as the first parameter, and success as the second. So all we need to do is make a tuple (multiple variables on the same line, I guess is an easy way to explain it) with the function.

local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

The above code will store both the player's icon, if it loaded, and a bool value that is true if it actually loaded, and false if not. Below is an example of how to incorporate this into your code.

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local userId = player.UserId
local thumbType = Enum.ThumbnailType.AvatarBust
local thumbSize = Enum.ThumbnailSize.Size352x352
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

if isReady == true then
	script.Parent.Image = content
else
	script.Parent.Image = "rbxassetid://0" -- default image in case of their icon not loading
end

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