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

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

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()

4 comments

0

I fixed the (unfortunate) typo in your question title.

0

Thanks B)

0

What is the Point of the coroutine 'spawn' on line 27? Why is it needed there?

0

I put it there in hopes that it would do something, is was just random I guess. I really need an answer soon :/

1 answer

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

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