So I'm playing around with the Disaster Kit V2 and I made a map rotation system, and I want to make every map have a different background music, but when the map changes, the song keeps playing. How can I make it so specific music only plays on it's specific map?
Here's the script for the map changing if it helps:
function regenStructures() workspace.Structures:ClearAllChildren() local maps = game.ServerStorage.Clones.Maps:GetChildren() local mapCopy = maps[math.random(1, #maps)]:Clone() mapCopy.Parent = workspace.Structures mapCopy:MakeJoints() end
Here's my concept, why not make a folder where you store your audios?
So if you have audio sound stored in your folder, it should be like this. (make sure sounds are named)
local sound = Instance.new("Sound", game.Workspace) local bm = --location of the folder local st = bm.--(sound in folder you want to play) local en = bm.--(sound you want to stop) function regenStructures() workspace.Structures:ClearAllChildren() local maps = game.ServerStorage.Clones.Maps:GetChildren() local mapCopy = maps[math.random(1, #maps)]:Clone() mapCopy.Parent = workspace.Structures mapCopy:MakeJoints() wait(1) en.--(audio in the folder currently playing).Sound:Stop() sound.Looped = true st.--(audio that you want to play next).Sound:Play() end
If you have any errors or questions about this, feel free to ask, and I might edit this again.