Stage music help?

I’m trying to get music to play depending on an Intvalue in StarterPlayer (I don’t know where i’d need to put it)

When I teleport to the next level I don’t get any errors in my output but the music doesn’t change or stop. Here is my test script

if script.Parent.Value == 2 then
	game.Workspace.Music.Stage1:Stop()
	wait(0.2)
	game.Workspace.Music.Stage2:Play()
end

Assuming this is music that should be playing for one person only, put the value in ReplicatedStorage and connect it to a localscript.
As for your code, you’ll probably need to assign it to an event. (.Changed works)

How would I connect it to a localscript? And how would .changed work? I need specific tracks to play for specific stage numbers instead of just general when it changes

Use the .Changed (or GetPropertyChangedSignal) event on your value.
What it does is pick up on any changes made to the value, allowing you to run some code if it does.

Alternatively, you can listen for a .Touched event.

I suppose I could have some sort of stage handler script somewhere that has a long line of "(level number gate).touched and then play the appropriate music, it’d be super long and untidy but I guess it’d work

At that point it depends on how your game is designed.

You must be using a server script to teleport a player to the next stage/level. So in order to change the music, you can use a RemoteEvent and fire it when the player gets teleported. And then insert a local script maybe into startergui, define the sound and try changing it from there.
Edit: I forgot to mention, FYI use FireClient(player)

Is there something specific (aside from security of course) that warrants putting the localscript into StarterGui?
It might be better to have 1 localscript.

From what I know, local scripts only work if parented to these folders:

Tools,
StarterGui,
StarterPack,
StarterPlayerScripts,
StarterCharacterScripts.

I am pretty sure they don’t work if parented to a part/model in workspace or workspace itself and thats why I asked him to parent the local script to StarterGui, If I missed something lemme know.

1 Like