Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I check if a SoundId is real or just random text?

So I want to make a script where it checks if a submitted sound is valid or if it might break the script. I can't use "IsLoaded" because it can only use one sound. However, I was wondering if there is some kind of service I can use to check if it's the real deal or not? Here is what I have so far:

--Variables
local PresetId = {}--Preset music
local ItemId = 1006878233--Item ID for buying music

--Objects
local Sound = script.Parent.Sound
local Queue ={}
local System = script.Parent
local MS = game:GetService("MarketplaceService")
local Product = 1006878233

--SoundID function

function IsValidSound(soundId) --either returns false or valid sound
    local con1, con2, yieldFolder, valid
    local sound = Instance.new("Sound", workspace)
    local function cleanup()
        con1:disconnect()
        con2:disconnect()
        yieldFolder.Name = "Different"
    end
    yieldFolder = Instance.new("Folder")
    con1 = game:GetService("LogService").MessageOut:connect(function(msg, msgType)
        if msgType ~= Enum.MessageType.MessageError then return end 
        if not msg:find(tostring(soundId)) then return end
        valid = false
        cleanup()
    end)    
    con2 = sound.Loaded:connect(function()
        valid = sound.TimeLength > 0
        cleanup()
    end)
    sound.SoundId = soundId
    if sound.IsLoaded then --already loaded
        cleanup()
        if sound.TimeLength == 0 then
            sound:Destroy()
            return false
        end
        return sound
    end
    yieldFolder.Changed:wait() --wait for either event to occur
    yieldFolder:Destroy()
    if not valid then sound:Destroy() end
    return valid and true
end

for i,item in pairs(script.Parent:GetChildren()) do
	if item:IsA("Model") then
		print("Booth!")
		local Screen = game.StarterGui:FindFirstChild(item.Name)
		local Submit = item.Button.ClickDetector
		local Box = Screen.IDBox
		Submit.MouseClick:Connect(function(player)
			print("Submitted")
			if IsValidSound(Box.Text) == false then
				Box.Text = "Invailid ID!"
				print("Invailid")
			else
				MS:PromptProductPurchase(ItemId,player)
			end
		end)
	end
end

I tried using a premade function but it did not work! It just kept saying "Submitted" in the output! Can anyone help me? Thanks if you can ;)

1 answer

You can use GetProductInfo and if the asset type is audio and it doesn't throw a error (it will if the assetid is invalid), then you can say its valid, if not, its invaild.

Example:

if pcall(function() 
	Asset = game:GetService("MarketplaceService"):GetProductInfo(assetid)
end) then
	if Asset.AssetTypeId == 3 then
		print("is vaild audio")
	else
		print("is not vaild audio")
end
else
	print("is not vaild audio")
end

2 comments

0

Sorry that does not work. It said not valid even though it IS valid.

0

Because it has to be an audio, just like you asked for, "1006878233" is a place not an audio

This discussion is preserved as it was. New answers, comments, and votes are closed.