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
I fixed the (unfortunate) typo in your question title.
Thanks B)
What is the Point of the coroutine 'spawn' on line 27? Why is it needed there?
I put it there in hopes that it would do something, is was just random I guess. I really need an answer soon :/