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

Why is my sound ID input system not working? FIXED

Asked by 4 years ago
Edited 4 years ago

So im trying to make a system where a player can put a sound ID for some cash and play that sound

local button = script.Parent
local soundBox = button.Parent.SoundBox
local event = game.ReplicatedStorage.AdviceSound
local db = game.ReplicatedStorage.DiscoDebounce
local plr = game.Players.LocalPlayer
local marketplaceService = game:GetService("MarketplaceService")

button.MouseButton1Click:Connect(function()
    if db.Value == false then
        if plr.leaderstats.Cash.Value >= 300 then
            local input = soundBox.Text
            local convertion = tonumber(input)
            if convertion ~= nil then
                local asset
                local success, result = pcall(function()
                    asset = marketplaceService:GetProductInfo(convertion, Enum.InfoType.Asset)
                end)

                if success and asset.AssetType == 3 then
                    event:FireServer(convertion)
                    print(success)
                elseif not success then
                    button.Text = "Invalid ID"
                    button.BackgroundColor3 = Color3.new(255, 0, 0)
                    wait(2)
                    button.Text = "Apply ($300)"
                    button.BackgroundColor3 = Color3.new(0, 255, 0)
                    print(result)
                end
            end
        end
    end
end)

db.Changed:Connect(function()
    if db.Value == true then
        button.Text = "Cooldown"
        button.BackgroundColor3 = Color3.new(255, 0, 0)
    else
        button.Text = "Apply ($300)"
        button.BackgroundColor3 = Color3.new(0, 255, 0)
    end
end)

event.OnClientEvent:Connect(function(name, duration)
    local fixedDuration = math.ceil(duration)
    button.Parent.SoundName.Text = "Name: "..name
    for i = fixedDuration, 0, -1 do
        button.Parent.Time.Text = "Time: "..tostring(i)
        wait(1)
    end
    game.ReplicatedStorage.SoundFinished:FireServer()
    button.Parent.SoundName.Text = "Name:"
    button.Parent.Time.Text = "Time:"
end)

and there is a pcall function that checks if the ID put by the user is a valid audio ID but even though I put a valid audio ID the if statement under the pcall doesn't detect it as an AssetType 3 (audio type)?

0
Is there an error code in the output? Id yes what is it jhjryoutube 29 — 4y
0
I fixed it 0Papa_Rat0 63 — 4y
0
The problem was that it was AssetTypeId not AssetType 0Papa_Rat0 63 — 4y
0
But thanks for the help! 0Papa_Rat0 63 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I fixed it

The problem was that it was AssetTypeId not AssetType

Ad

Answer this question