You must send a get request using HttpService and then :FromJSON. Then index into imageUrl to get the Url. This gives you a nice crispy good looking image.
Unfortunately this only produces a ROBLOX oriented render. What we are attempting to do here is linkify it for external access, for example in this case, it’s for Discord.
There are several proxy services like Hyra, but if you’re concerned about privacy, then there are tutorials and open-sourced projects around the internet on creating your own proxy services, so you might want to check those out.
If it’s from a Roblox server then, GetUserThumbnailAsync() can be used, since it will only return a tuple containing the image url and a boolean to check if its loaded or not.
local http = game:GetService("HttpService")
local function getheadshot(userid)
local s, data = pcall(function()
return http:JSONDecode(http:GetAsync(`https://thumbnails.roproxy.com/v1/users/avatar-headshot?userIds={userid}&size=420x420&format=Png&isCircular=false`))
end)
if s and data then
return data.data[1].imageUrl
else
return "https://t3.rbxcdn.com/9fc30fe577bf95e045c9a3d4abaca05d" --example, if it was not possible to get an avatar
end
end
print(getheadshot(1)) --> https://tr.rbxcdn.com/ea3425c2b657de9af16c629441e0dcb2/420/420/AvatarHeadshot/Png