Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Radio Script Not Detecting If The Audio Is Deleted And Still Creates Sound Asset To Try To Play It?

Asked by
LuaDLL 253 Moderation Voter
3 years ago

The Script Is Supposed To Check If The Asset Is Valid and not Invalid and/or Content Deleted but it always returns true?

sg.ui.play.MouseButton1Click:Connect(function()
        local id = sg.ui.id
        local Audio = false
        local notanumber = false
        if tonumber(id.Text) then
            local product = mps:GetProductInfo(tonumber(id.Text))
            if product.AssetTypeId == 3 then
                Audio = true
            end
        else
            sg.ui.id.Text = "Not A Asset Id."
            notanumber = true
        end
        if Audio and not notanumber then
            local cp = game:GetService("ContentProvider")

            local function isSoundValid(id)
                local isValid = false

                local sound = Instance.new("Sound")
                sound.SoundId = "rbxassetid://"..id

                cp:PreloadAsync({sound}, function(_, status)
                    isValid = status == Enum.AssetFetchStatus.Success
                end)

                sound:Destroy()

                return isValid
            end

            wait()

            print(isSoundValid(tonumber(id.Text)))

            if isSoundValid(tonumber(id.Text)) then
                Remote:FireServer("PlaySong", tonumber(id.Text))
                sg:Destroy()
                songgui = nil
            else
                sg.ui.id.Text = "Sound Is Either Deleted Or Failed To Load."
            end
        elseif not Audio and not notanumber then
            sg.ui.id.Text = "Not A Valid Audio Asset Type."
        end
    end)

Answer this question