ランダムに表示される絵画を作ろう!

https://youtu.be/e-O02gGXsIA

local decal = script.Parent.Art1.Decal
local click = script.Parent.Art1.ClickDetector
local particle = script.Parent.Art1.ParticleEmitter
local pop = script.Parent.Art1.pop

local random = Random.new()

local marketplace = game:GetService("MarketplaceService") --アセットの情報を読み込むためにまず必要

local function clicked() --Art1がクリックされたらこれを実行
	print("クリック!")
	click.MaxActivationDistance = 0 --連打防止
	
	while true do
		local randomID = random:NextInteger(500000,2000000000) --かっこに囲まれた範囲の中から数字を選ぶ
		
	print("探し中")
	local success, info = pcall(function()
	return marketplace:GetProductInfoAsync(randomID,Enum.InfoType.Asset) --アセットの情報を読み込みinfoに送る
		end) --エラーによるスクリプトの停止を防ぐ
	
		if not success then --アセット情報の読み込みに失敗した場合
			print("失敗!")
		    continue --whileの最初に戻る
	end
		
		if info.Description == "Shirt Image" or info.Description == "Pants Image" or info.Description == "TShirt Image" then --画像の説明文に「Shirt Image」か「Pants Image」か「TShirt Image」が書かれていたら
			print("これは服のテクスチャ!")
			continue --whileの最初に戻る
		end
		
		if info and info.AssetTypeId == 1 then --randomIDのアセットの種類が1(画像)だった場合
			print("成功!")
			decal.Texture = "rbxassetid://"..randomID --decalの画像をrandomIDに差し替える
			particle.Enabled = true
			pop:Play()
			wait(3)
			particle.Enabled = false
			click.MaxActivationDistance = 32 --連打防止解除
		    break --whileのループをぶっ壊す!
	end
	
    task.wait()
		
		end
end

click.MouseClick:Connect(clicked)--Art1がクリックされたらclickedを実行