How do I stop it from stopping each time it errors? I'm making a random game advertisement board (for fun) but it keeps on stopping whenever it doesn't find an asset. But I want the script to ignore that and keep going. How do I achieve this?
local marketplace = game:GetService('MarketplaceService') while wait(3) do local min = 1 local max = 9999999999 local placeId = math.floor(math.random() * (max - min) + min) script.Parent.Texture = "https://www.roblox.com/asset-thumbnail/image?assetId="..placeId.."&width=768&height=432&format=png" print(placeId) local info = marketplace:GetProductInfo(placeId) script.Parent.Parent["Advertise!"].TextLabel.Text = info.Name end
PCall Should Help.
Some Documentation: devforum.roblox.com/t/pcalls-when-and-how-to-use-them/393687 devforum.roblox.com/t/pcall-function/227937 devforum.roblox.com/t/how-to-use-pcall/448345 devforum.roblox.com/t/pcalls-when-and-how-to-use-them/393687
So you could do
local marketplace = game:GetService('MarketplaceService') while wait(3) do local success, response = pcall(function() local min = 1 local max = 9999999999 local placeId = math.floor(math.random() * (max - min) + min) script.Parent.Texture = "https://www.roblox.com/asset-thumbnail/image?assetId="..placeId.."&width=768&height=432&format=png" print(placeId) local info = marketplace:GetProductInfo(placeId) script.Parent.Parent["Advertise!"].TextLabel.Text = info.Name end) end