How could i integrate music playing in a certain map with this script?

ok, I recently followed a tutorial to make a script, i won’t lie. but how would i convert this to play music if a certain map name is chosen?

the two maps are Crossroads and Desert, and i was thinking of something like

if currentmap.Name = Crossroads then 
music:Play()
end

but i’m not sure if that would work. so could i get some advice/help?

local mapfolder = game.Lighting.Maps
local maps = mapfolder:GetChildren()
local roundtime = script.RoundTime

while true do
print ("loop starting")
	local chosenmap = maps[math.random(1,#maps)]
	local currentmap = chosenmap:Clone()

	currentmap.Parent = game.Workspace
	currentmap:MakeJoints()
print (chosenmap.Name)
print ("was chosen!")

print("now initating a wait till next round")
wait(20)
	print("map destroyed, restarting loop")
	currentmap:Destroy()
end

Make a folder for the music, like you have with the maps.
Put the music in the folder and make sure to name it the same as the map.
Then When selecting the map you could get the music as:

local music = musicFolder[chosenmap.Name]:Clone()
music.Parent = workspace
music:Play()

Then stop the music and destroy it when the map ends.

1 Like

it worked! this is great. thank you so much!