Get random decal ID

I want to make a script that gets a random decal ID, but how would I do that? I have tried using the getfreedecals() function.

I think your best bet would be to do a math.random for loop through the getfreedecals().

Note: this can be risky with bypassed images.

4 Likes

How would I do the same with videos?

Looking for decals will cause errors. Look for images instead.

while wait() do
	success = false -- success is false unless there is an image id found
	pcall(function() -- so it doesn't error
		id = math.random(1,1000000000) -- random id
		if game.MarketplaceService:GetProductInfo(id).AssetTypeId==1 then success = true end -- make sure the id is an image id
	end)
	if success then game.Players.formy2kids.PlayerGui.ScreenGui.ImageLabel.Image = "rbxassetid://"..id end -- if it is an image id then make some decal/imagelabel use the random image
end

This script uses the MarketplaceService to check a random id and make sure it is an image (AssetTypeId is 1 when it is an image). If a random image is found, you can change a decal/imagelabel to use the image, put the id in a table, etc. You can use this kind of script to find any random asset. You can also use this for manually typing in ids because you won’t have a ton of errors in the console using pcall. (You will still get errors with deleted images, and I’m not an expert so I don’t know how to fix that)

4 Likes

I don’t know; I don’t think there’s a getvideos() function yet.