I have a script that generates a totally random image, but the problem is that it does not do it all the time because I don’t know how to make it detect if the the image exists on the roblox website
script.Parent.Parent.ENTER.MouseButton1Down:Connect(function(hit)
local mamf = math.random(10000000,20000000)
local info = game:GetService('MarketplaceService'):GetProductInfo(mamf, Enum.InfoType.Asset)
if info and info.AssetTypeId == 13 then
script.Parent.Image = "rbxassetid://" .. mamf
print(script.Parent.Image)
else
print(' ')
end
end)
But the problem is that i want it to do loops until it finds a valid image everytime the player presses the button or else it will appear blank sometimes
The repeat <code> until <condition> loop executes the <code> until the <condition> is true.
script.Parent.Parent.ENTER.MouseButton1Down:Connect(function(hit)
local mamf
local info
repeat
mamf = math.random(10000000,20000000)
info = game:GetService('MarketplaceService'):GetProductInfo(mamf, Enum.InfoType.Asset)
task.wait()
until info and info.AssetTypeId==13
script.Parent.Image = "rbxassetid://" .. mamf
print(script.Parent.Image)
end)
The code above will repeatedly assign mamf a random id and info to the product (if found) until the product is found and it is of type 13. Only then will the code resume to set the image id of the Parent to the first id found, and print the id.