local market = game:GetService("MarketplaceService")
local active = false
local function randomdecal()
for _, v in pairs (workspace.DecalParts:GetChildren()) do
local id = math.random(1,10000000)
local decal = v:findFirstChildOfClass("Decal")
local success = false
pcall(function()
if market:GetProductInfoAsync(id).AssetTypeId == 1 then
success = true
if success == true then
print("decal found :)")
decal.Texture = "rbxassetid://"..id
else
print("fails :p")
randomdecal()
end
end
end)
end
end
randomdecal()
Could you provide me with Info about the folder workspace.DecalParts so I can try to recreate it? Like are there just a bunch of random decal objects or smth?
When I do it, it stop around 20. Im guessing there’s some sort of yielding happening indefinitely and some sort of timeout is needed. I’ll try working on it some more.
Alr I figured it out. Whenever the random Id wasn’t valid, it would move on to the next DecalPart without retrying for another random Id. Instead, whenever an Id wasn’t valid it would move on to the next DecalPart and completely skip the previous.
This code works:
local market = game:GetService("MarketplaceService")
local active = false
local function GetAValidRandomDecal(): number
--Repeats until it finds a valid decal id then returns the id
while true do
local id = math.random(1,10000000)
local success, err = pcall(function()
if game.MarketplaceService:GetProductInfoAsync(id).AssetTypeId ~= 1 then
--if id is valid but isn't assetTypeId 1 then the id isn't valid so it repeats
error("Not a decal")
end
end)
--if found return
if success then
print("decal found :)")
return id
end
end
end
local function randomdecal()
for _, DecalPart in pairs (workspace.DecalParts:GetChildren()) do
--Creates new thread for each decal part to speed up the script
--I would highly recomend using Github:Eveara/promise for something like this
task.spawn(function()
local id = GetAValidRandomDecal()
DecalPart:FindFirstChildOfClass("Decal").Texture = "rbxassetid://"..id
end)
end
end
randomdecal()