Stop() doesn't stop music

Hello!

I’m making a script for a round-based game that plays music in lobby and the minigames. The issue is, when I run stop on the music, it doesn’t stop. I don’t know what’s causing the problem, and I don’t really want to bump an old thread from 7 years ago about my same issue. Help is appreciated!

local LobbyFolder = SoundService.Lobby
local ActionFolder = SoundService.ActionFolder

local LobbyMusic = LobbyFolder:GetChildren()[math.random(#LobbyFolder:GetChildren())]
local ActionMusic = ActionFolder:GetChildren()[math.random(#ActionFolder:GetChildren())]

The Play and stop function are both in a while true do loop, but they also stop playing in the loop.
(I’m playing both lobby and action music)

Would you mind sharing the playing/stopping script?

But the play and stop functions are in the game script, which controls the whole game, meaning I;d probably have to show the whole script, if that’s fine.

Yeah that’s fine. You can delete all of the lines that don’t have anything to do with this issue so it’s shorter if you want.

local LobbyFolder = SoundService.Lobby
local ActionFolder = SoundService.ActionFolder

local LobbyMusic = LobbyFolder:GetChildren()[math.random(#LobbyFolder:GetChildren())]
local ActionMusic = ActionFolder:GetChildren()[math.random(#ActionFolder:GetChildren())]

while true do
	LobbyMusic:Play()
	timer = 20
	repeat
		timer -= 1
		Status.Value = "Intermission: "..timer
		wait(1)
	until timer == 0
	local ChosenMap = Maps[math.random(#Maps)]
	local Map = ChosenMap:Clone()
	Map.Parent = workspace
	wait(0.5)
	Status.Value = "The map is... "..ChosenMap.Name
	wait(3)
	Status.Value = "Loading Map..."
	LobbyMusic:Stop()
	repeat
		wait(1)
		timer -= 1
		Status.Value = "Round starting in "..timer
	until timer == 0
	local PartToDelete
	ActionMusic:Play()
	ActionMusic:Stop()

There’s more to the script, but I cut them out to make it shorter

I’ve had some problems with sounds parented to the sound service in the past. Try moving them to the workspace and tell me if the problem persists.

2 Likes