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

Audio refuses to stop after a repeat loop, how to fix?

Asked by 9 years ago

I am having trouble with my code. It seems as if the script refuses to stop the already playing audio after a repeat loop. It is highly annoying because it will overlap with the music that plays after the loop and make a big obnoxious mess of sound. How do I prevent this??

CODE:

local soundss = game.Workspace.RoundMusic:GetChildren()
        local soundw = soundss[math.random(1,#soundss)]
        local sounddd = soundw:Clone()
        sounddd.Parent = game.Workspace
        sounddd:Play()
        sounddd:Destroy()
        local sum = 0
        local num = 0
        local tiem = 120 --[[120]]
        repeat
            sum = 0
            for p,d in pairs (game.Players:GetChildren()) do
                coroutine.resume(coroutine.create(function()
                    d.PlayerGui.TopBar.Frame.TextLabel.Text = "There are "..tiem.." seconds left to tag the runners!"
                end))
                if d.RoleVal.Value == 1 then
                    sum = sum + 1
                end
                if d.RoleVal.Value == 2 then
                    num = num + 1
                end
            end
            tiem = tiem - 1
            wait(1)
        until tiem == 0 or sum == 0 or num == 0
        wait(1)
        spawn(function()
            sounddd:Stop()
        end)
        sounddd = nil
        soundss = game.Workspace.Sounds:GetChildren()
        soundw = soundss[math.random(1,#soundss)]
        sounddd = soundw:Clone()
        sounddd.Parent = game.Workspace
        sounddd:Play()
        sounddd:Destroy()
0
I fixed the (unfortunate) typo in your question title. User#11893 186 — 9y
0
Thanks B) FOXmcloud021 5 — 9y
0
What is the Point of the coroutine 'spawn' on line 27? Why is it needed there? TheeDeathCaster 2368 — 9y
0
I put it there in hopes that it would do something, is was just random I guess. I really need an answer soon :/ FOXmcloud021 5 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I answered myself, I Destroyed the sound before I could access it again LOL Thanks!

Ad

Answer this question