Different music for each stage

I want to create a script that can check the stage number and if it’s in a specific range, play music, if it’s in another range, play another song, would this be the best code to use?

Group1 = {
1;
2;
3;
4;
5;
6;
7;
8;
9;
10;
}

local ID = script.Sound.SoundId
local Volume = script.Sound.Volume

game.Players.PlayerAdded:Connect(function(Player)
if script.Parent.Parent.Parent:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value == Group1 then
ID = "rbxassetid://3182738096"
Volume = 2.5
end
end)

Here’s an image of the code:

Why don’t you just have the sounds named by what stage it goes to inside a folder, and then depending on the name of the stage you would do

script.Sounds[Stage Instance.Name]

or

script.Sounds[Stage Leaderstats String.Value]

wherever you have the stage name stored.

2 Likes

Make a Region3 with music
Play music in different areas

1 Like

Here the tutorial:
make a Part and name it Area. He should be flat on the ground. Make a sound inside the part. Make the part CanCollide false and Anchored true.
Then Group it and rename the group Areas. Copy the part (Area) and make it in the same group.
then make a localsript into starterCharcaterScript ==>

local sound = Instance.new(“Sound”, script)
sound.Looped = true

local char = script.Parent
local hrp = char:WaitForChild(“HumanoidRootPart”)

local areasGroup = workspace:WaitForChild(“Areas”)

local currentArea = nil

game:GetService(“RunService”).Heartbeat:Connect(function()

local raycast = Ray.new(hrp.Position, hrp.CFrame.UpVector * -1000)

local part = workspace:FindPartOnRayWithWhitelist(raycast, {areasGroup})


if part and part.Parent == areasGroup then
	
	if part ~= currentArea then
		
		currentArea = part
		
		sound.SoundId = currentArea.Music.SoundId
		sound:Play()
	end	
	
else
	
	currentArea = nil
	sound:Stop()
end

end)

thats all.
When you touch the Part, the music plays.

1 Like

I didn’t want to make a part, I wanted the obby to check the stage number and if it’s in a certain range play a certain song, is that impossible?

All is possible but this is the simple way.

1 Like

If I understood clearly,

Whenever the player reaches a specific point in the obby or a specific area, a music plays?

1 Like

Is the advanced way even better?

Yeah, and I wanted to make it where there’s multiple songs when you reach certain stages.

You could try to do this (in a local script inside the playergui):

local musics = script -- Change to where you want your musics to be.
local plr = game.Players.LocalPlayer
local obbystatus = plr:WaitForChild("ObbyStatus") -- Change to whatever the value is.
local selectedMusic = nil

obbystatus.Changed:Connect(function()
    selectedMusic = musics[obbystatus.Value]
    selectedMusic:Play()
    for i,v in pairs(musics:GetChildren()) do
        if v ~= selectedMusic then
            v:Stop()
        end
    end
end)

I haven’t tested it as I am currently celebrating the New Year and I kind of rushed this script.
Sorry for the wait and happy New Year!

(I saw you liked my post, you might mark it as a Solution if it worked, if it didn’t, let me know!)

2 Likes