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

When I mute the music, I can't make it play back, what happened?

Asked by 5 years ago
local function songs ()
    while true do
        game.Workspace.Songs.DarudeSand:Play()
        wait(123)
        game.Workspace.Songs.Bangarang:Play()
        wait(94)
        game.Workspace.Songs.ET:Play()
        wait(119)
        game.Workspace.Songs.Poison:Play()
    end

    songs()


    script.Parent.Parent.StarterGui.ShopAct.Frame.ImageButton.MouseButton1Click:Connect(function()
        if game.Workspace.Songs ~= nil then
        game.Workspace.Songs:Destroy()
        elseif game.Workspace.Songs == nil then
            game.ReplicatedStorage.Songs:Clone(workspace)
        songs()

        end

    end)

Whenever I try to unmute the music, the output says that Songs doesn't belong to workspace anymore but that's why I added the elseif

1
If something may not exist, use Instance:FindFirstChild() Optikk 499 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Here, I have a way better solution -- you don't have to delete anything!

local play = true
local debounce = false
local Songs = game.Workspace.Songs

local function songs ()
    while true do
        Songs.DarudeSand:Play()
        wait(123)
        Songs.Bangarang:Play()
        wait(94)
        Songs.ET:Play()
        wait(119)
        Songs.Poison:Play()
end

songs()


  script.Parent.Parent.StarterGui.ShopAct.Frame.ImageButton.MouseButton1Click:Connect(function()
    if debounce == false then
        debounce = true
            if play == true then
                play == false
            elseif play==false then
                play == true
            end
        for i,v in pairs(Songs:GetChildren())
            if v:IsA("Sound") then
                if play == false then
                    v:Pause()
                elseif play == true then
                    v:Resume()
                end
            end
        end
    wait(1)
    debounce == false
    end
end)

I simply defined a boolean value that can be set to true or false judging by the button press, a debounce is added so it isn't constantly changing the value.

Once the "if" statements decide whether to be false or true, it then does a loop of the Songs folder/model and checks if a certain member of the model (v) is a sound. Once it figures that out, it pauses or resumes it judging by whether play is false or true.


Although, if you want, I do have a huge module script that you could use to play your songs alternatively instead of ":Play()"

https://forum.scriptinghelpers.org/topic/725/cvextra-super-module-script

MODULE SCRIPT: https://www.roblox.com/library/2674126390/CVExtra-Super-Module-Script

A remade form using my script (THIS ASSUMES YOU PUT THE MODULE SCRIPT IN THE WORKSPACE):

local play = true
local debounce = false
local Songs = game.Workspace:FindFirstChild("Songs")
local CVExtra = game.Workspace:FindFirstChild("CVExtra")
local playAudio = CVExtra.playAudio

local function songs ()
    while true do
        playAudio(Songs.DarudeSand)
    wait(0.5)
        playAudio(Songs.Bangarang)
        wait(0.5)
        playAudio(Songs.ET)
        wait(0.5)
        playAudio(Songs.Poison)
end

songs()


  script.Parent.Parent.StarterGui.ShopAct.Frame.ImageButton.MouseButton1Click:Connect(function()
    if debounce == false then
        debounce = true
            if play == true then
                play == false
            elseif play==false then
                play == true
            end
        for i,v in pairs(Songs:GetChildren())
            if v:IsA("Sound") then
                if play == false then
                    v:Pause()
                elseif play == true then
                    v:Resume()
                end
            end
        end
    wait(1)
    debounce == false
    end
end)

Do not worry about doing a whole wait of the song's length, my module script has that all done for you, and it'll wait if the audio gets paused.

Ad

Answer this question