So I am creating a system where moderators can approve or deny images coming through and this is the preview button that loads the image ID given onto a loading screen.
script.Parent.MouseButton1Click:Connect(function()
script.Parent.TextColor3 = Color3.fromRGB(255,255,255)
local success,err = pcall(function()
script.Parent.Parent.Selected.Image = "https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=" .. script.Parent.Parent.ThumbnailId.Text
end)
if not success then
script.Parent.Parent.Selected.Success.Value = false
game.StarterGui:SetCore("SendNotification", {
Title = "Billboard Rental",
Text = "Something went wrong? Make sure that you are only trying to preview the number in the decal URL.",
Icon = "http://www.roblox.com/asset/?id=4481760722",
Duration = 7,
})
else
script.Parent.Parent.Selected.Success.Value = true
end
end)
My issue is that the pcall isn’t detecting when the image fails to load and nulled images can be given. Is there a way to check if the image has errored BEFORE the script ends so I can send the user a message saying their ID couldn’t be loaded?
In my opinion it doesn’t work because you are not returning a value to a pcall. Try this code:
script.Parent.MouseButton1Click:Connect(function()
script.Parent.TextColor3 = Color3.fromRGB(255,255,255)
script.Parent.Parent.Selected.Image = "https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=" .. script.Parent.Parent.ThumbnailId.Text
local success,err = pcall(function()
if script.Parent.Parent.Selected.Image == "https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=" .. script.Parent.Parent.ThumbnailId.Text then
return true
else
return false
end
end)
if err ~= true then
script.Parent.Parent.Selected.Success.Value = false
game.StarterGui:SetCore("SendNotification", {
Title = "Billboard Rental",
Text = "Something went wrong? Make sure that you are only trying to preview the number in the decal URL.",
Icon = "http://www.roblox.com/asset/?id=4481760722",
Duration = 7,
})
else
script.Parent.Parent.Selected.Success.Value = true
end
end)
script.Parent.MouseButton1Click:Connect(function()
script.Parent.TextColor3 = Color3.fromRGB(255,255,255)
local function getStatus(contentId,status)
if contentId == "https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=" .. script.Parent.Parent.ThumbnailId.Text then
if status == false then
game.StarterGui:SetCore("SendNotification", {
Title = "Billboard Rental",
Text = "Something went wrong? Make sure that you are only trying to preview the number in the decal URL.",
Icon = "http://www.roblox.com/asset/?id=4481760722",
Duration = 7,
})
else
script.Parent.Parent.Selected.Image = contentId
end
end
end
game:GetService("ContentProvider"):PreloadAsync({"https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=" .. script.Parent.Parent.ThumbnailId.Text},getStatus)
end)
EDIT
I’ve found that status is not equal to true/false, rather it’s enums. Thanks for your help!