Hello! Currently I am trying to make a simulator game at the moment and I want a script that sends a webhook whenever someone hatches an exclusive pet. This is what I have so far but right now it is returning the fall back image. Does anyone know how to fix this by chance?
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NotifyMegaHatch = ReplicatedStorage:WaitForChild("NotifyMegaHatch")
local webhookUrl = "Webhook Url Here"
NotifyMegaHatch.OnServerEvent:Connect(function(player, Egg, Result, EggHatched, PetImage)
-- Validate PetImage
if not PetImage or not PetImage.Value then
warn("Invalid PetImage")
return
end
-- Ensure assetId is numeric
local assetId = tostring(PetImage.Value):match("%d+")
if not assetId then
warn("Invalid asset ID: "..tostring(PetImage.Value))
return
end
-- Build the roproxy thumbnails API URL
local function getThumbnailUrl(assetId, retries, delay)
retries = retries or 5
delay = delay or 1 -- seconds
local apiUrl = "https://thumbnails.rotunnel.com/v1/assets?assetIds="..assetId.."&size=420x420&format=Png&isCircular=false"
for i = 1, retries do
local success, response = pcall(function()
return HttpService:GetAsync(apiUrl)
end)
if success then
local data = HttpService:JSONDecode(response)
local thumbnailData = data.data[1] and data.data[1].imageUrl
if thumbnailData then
if thumbnailData.state == "Completed" and thumbnailData.imageUrl then
return thumbnailData.imageUrl
end
end
end
wait(delay) -- wait before trying again
end
return "https://tr.rbxcdn.com/default/420/420/Image/Png"
end
local thumbnailUrl = getThumbnailUrl(assetId)
print("Using thumbnail URL:", thumbnailUrl) -- Prepare Discord payload
local jsonData = HttpService:JSONEncode({
embeds = {{
title = "Exclusive Pet Hatched",
description = Result .. " has been hatched by " .. player.Name .. "!",
color = 0xFF0004,
fields = {
{name = "Rarity", value = "Exclusive", inline = true},
{name = "Egg", value = tostring(Egg), inline = true},
{name = "EggHatched", value = "Total Eggs Hatched: "..tostring(EggHatched), inline = true},
},
image = {url = thumbnailUrl}
}}
})
-- Send webhook safely
local postSuccess, postErr = pcall(function()
HttpService:PostAsync(webhookUrl, jsonData, Enum.HttpContentType.ApplicationJson)
end)
if not postSuccess then
warn("Failed to send Discord webhook: "..tostring(postErr))
end
end)
I believe this line is the one causing the issue.
I’m thinking that the line is setting thumbnailData to the imageUrl. You are then trying to view the .state and .imageUrl of the image url.
A possible fix would be to replace
local thumbnailData = data.data[1] and data.data[1].imageUrl
if thumbnailData then
with
local thumbnailData = data.data[1]
if thumbnailData and thumbnailData.imageUrl then
I’ll check it out, Thanks
charschars
I’m afraid that didn’t work. Thanks for the input though!
Actually - can you please provide an example of what your asset ID is?
I believe the thumbnail api is more for players, isn’t it?
Yes, A example of one of my assetIds is: 118288229496374
That Id DOES seem to work with the URL.
Can you please try commenting out the pcall and related code (so that any errors are visible), and also add print statements throughout to see which code is running and which code is not
Yup, I’ll get back to you afterwards
Ok, All of the script runs because of Prints and the webhook going through, There are no errors. The only issue in the script seems to be the image.
Can you please add a print statement on line 45 and tell me if it fires? (I suspect it does, but just want to double check).
Also please add a print statement just before line 38
The print on Line 38 (after “if thumbnailData.state == "Completed" and thumbnailData.imageUrl then”) did not fire. Does this help?
Yeah. It confirms where the issue is occuring. Can you please print out thumbnailData before the if statement?
Yup give me a minute
charschars
Ok, it prints out nil for the thumbnaildata
Can you please resend the code in its current state, just so I am referencing the latest version
Of course!
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NotifyMegaHatch = ReplicatedStorage:WaitForChild("NotifyMegaHatch")
local webhookUrl = "https://discord.com/api/webhooks/1405080285736996936/m216wKypiAQoUzLSAwYal1sColhR8IGMTyEncqlcCGuwt6A4omhEcjtko_3hoH_BLQ1o"
NotifyMegaHatch.OnServerEvent:Connect(function(player, Egg, Result, EggHatched, PetImage)
-- Validate PetImage
if not PetImage or not PetImage.Value then
warn("Invalid PetImage")
return
end
-- Ensure assetId is numeric
local assetId = tostring(PetImage.Value):match("%d+")
if not assetId then
warn("Invalid asset ID: "..tostring(PetImage.Value))
return
end
-- Build the roproxy thumbnails API URL
local function getThumbnailUrl(assetId, retries, delay)
retries = retries or 5
delay = delay or 1 -- seconds
local apiUrl = "https://thumbnails.rotunnel.com/v1/assets?assetIds="..assetId.."&size=420x420&format=Png&isCircular=false"
for i = 1, retries do
local success, response = pcall(function()
return HttpService:GetAsync(apiUrl)
end)
if success then
local data = HttpService:JSONDecode(response)
local thumbnailData = data.data[1]
print(thumbnailData)
if thumbnailData and thumbnailData.imageUrl then
print(thumbnailData)
if thumbnailData.state == "Completed" and thumbnailData.imageUrl then
print(thumbnailData)
return thumbnailData.imageUrl
end
end
end
wait(delay) -- wait before trying again
print("Delay Wait")
end
return "https://tr.rbxcdn.com/180DAY-a41f4ec8a96640b01c7c28946bea7bef/420/420/Image/Png/noFilter"
end
local thumbnailUrl = getThumbnailUrl(assetId)
print("Using thumbnail URL:", thumbnailUrl) -- Prepare Discord payload
local jsonData = HttpService:JSONEncode({
embeds = {{
title = "Exclusive Pet Hatched",
description = Result .. " has been hatched by " .. player.Name .. "!",
color = 0xFF0004,
fields = {
{name = "Rarity", value = "Exclusive", inline = true},
{name = "Egg", value = tostring(Egg), inline = true},
{name = "EggHatched", value = "Total Eggs Hatched: "..tostring(EggHatched), inline = true},
},
image = {url = thumbnailUrl}
}}
})
-- Send webhook safely
HttpService:PostAsync(webhookUrl, jsonData, Enum.HttpContentType.ApplicationJson)
end)
Can you please also add a print statement on line 34, to output data, and another just before it to output response?
yes, give me a moment!
charschasr