Webhook thumbnail not loading

Why isn’t my webhook player thumbnail loading

local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(Id.Value, thumbType, thumbSize)

print("Thumbnail loaded")
print(content)

	local data = 
			{
				["embeds"] = {{
					["title"] = "__**Player **__" ,
					["description"] = Name,
					["type"] = "rich",
					["color"] = tonumber(0xffffff),
					["fields"] = {
						{
							["name"] = "__Time in game: __"  ,
						["value"] = timeSpent .." ".. hourorminut,
							["inline"] = true
						},
						["thumbnail"]={
							["url"] = content,
						}
					}
					
				}}
			}

output:
10:21:45.617 Thumbnail loaded - Server - Webhook:26
10:21:45.617 https://www.roblox.com/headshot-thumbnail/image?userId=0&width=420&height=420&format=png

> UserId is 0.

Is that intentional? There’s no 0th user on Roblox, so there’d be no thumbnail to fetch for them. Check how you’re fetching the UserId again. Checking the thumbnail link would’ve also helped you to pinpoint a potential problem.

Id isn’t 0, its getting it from a player in playeradded, and adding it to an intvalue called Id

You sure about that? This looks like a 0 to me.

image

Going to need to see more code if you’re looking for help. The very part that’s problematic has been omitted from your code sample: the only thing you’re sharing is your webhook structure and the use of GetUserThumbnailAsync. These parts are correct, but whatever you’re doing to get the UserId doesn’t seem to be in that same correctness boat.

local Added = script.Parent.Added
local Id = script.Parent.Id
local Name =  script.Parent.name

game.Players.PlayerAdded:Connect(function(player)
	local added = tick()
	Added.Value = added
	Id = player.UserId
	Name = player.Name
end)

I see what i did wrong, I didnt assing the value

That’s why you should do some review of your own code and debugging before posting threads! If you did a quick review, you might’ve caught the problem. You’re just redefining a variable rather than actually assigning any values.

I changed it to

local Added = script.Parent.Added
local Id = script.Parent.Id
local Name =  script.Parent.name

game.Players.PlayerAdded:Connect(function(player)
	local added = tick()
	Added.Value = added
	Id.Value = player.UserId
	Name = player.Name
end)

but the output says
https://www.roblox.com/headshot-thumbnail/image?userId=0&width=420&height=420&format=png

game.Players.PlayerAdded:Connect(function(player)
	local added = tick()
	Added.Value = added
	Id.Value = player.UserId
	Name.Value = player.Name
end)
print(Id.Value)

it prints 0

local url = "url"

local http = game:GetService("HttpService")

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local Added = script.Parent.Added
local Id = script.Parent.Id
local Name =  script.Parent.name

game.Players.PlayerAdded:Connect(function(player)
	local added = tick()
	Added.Value = added
	Id.Value = player.UserId
	Name.Value = player.Name
	print(Id.Value)
end)

local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(Id.Value, thumbType, thumbSize)
print("Thumbnail loaded")
print(content)
game.Players.PlayerRemoving:Connect(function(player)
	local hourorminut = "minute(s)"
	local removing = tick()
	local timeSpent = removing - Added.Value
	timeSpent = timeSpent/60
	 
	if timeSpent >= 60 then
		hourorminut = "Hour(s)"
		timeSpent = timeSpent/60
	else
		timeSpent = math.ceil(timeSpent)
		end
		local data = 
			{
				["embeds"] = {{
					["title"] = "__**Player **__" ,
					["description"] = Name,
					["type"] = "rich",
					["color"] = tonumber(0xffffff),
					["fields"] = {
						{
							["name"] = "__Time in game: __"  ,
						["value"] = timeSpent .." ".. hourorminut,
							["inline"] = true
						},
						["thumbnail"]={
							["url"] = content,
						}
					}
				}}
			}
local finaldata = http:JSONEncode(data)

		http:PostAsync(url, finaldata)
		
	end)

here’s the whole code
it works
itworks

You posted your whole code sample while I was replying so I had to change my wording a bit. Anyhow.

Your id is still 0 because you have another oversight which is the way you define the id. PlayerAdded may not have fired before setting Id.Value, so by the time Id.Value is indexed for the GetUserThumbnailAsync call it’s still 0. You could simply fix this by moving the GetUserThumbnailAsync call into PlayerRemoving instead.

You should probably reconsider the way you’re creating this system, like not using a ValueObject here and instead going for a dictionary and putting everything in one script instead. Would be much easier and not weird to maintain.

  • When the player joins, log when they joined and add them to a dictionary.
  • When the player leaves, get their time. Do some calculations to find out how much they spent in the game, then send that in your webhook.

Roughly:

local Players = game:GetService("Players")

local playerJoinTimes = {}

local function playerAdded(player)
    local timeNow = DateTime.now() -- You can also just use os.time()
    playerJoinTimes[player.UserId] = timeNow
end

local function playerRemoving(player)
    local joinTime = playerJoinTimes[player]
    -- If they were not tracked, do nothing
    if not joinTime then return end

    local timeNow = DateTime.now()
    local timeInGame = timeNow.UnixTimestamp - joinTime.UnixTimestamp

    -- Do some math with timeInGame to find out how long they've played.
    -- timeInGame will be in seconds; up to you to convert to minutes/hours.
    -- You can also use this to send via the webhook.
end

Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoving)
for _, player in ipairs(Players:GetPlayers()) do
    playerAdded(player)
end
1 Like