Music changes for everyone instead of one specific person

So I have this script where when you touch the specific spawn point, the music changes to a different song, and it works. The problem is, the song changes for everybody in the server, rather than just you only. I’m sure it’s an easy fix, but I have no idea what to do.

script:

function playSong1()
	game.SoundService.Songs.Stage1.Playing = true
	game.SoundService.Songs.Stage2.Playing = false
end
function playSong2()
	game.SoundService.Songs.Stage1.Playing = false
	game.SoundService.Songs.Stage2.Playing = true
end
playSong1()
workspace.Checkpoints.Stage2.Touched:Connect(playSong2)

You could use RemoteEvents for that :wink:

Basically, they’re capable of handling 1 way transportation (Server-Client/Client-Server)
In this instance, you’re wanting to change the song for 1 player only when they touch the part

So for this, we can insert a RemoteEvent inside ReplicatedStorage & add a bit more onto our code:

--Server
function playSong1()
	game.SoundService.Songs.Stage1.Playing = true
	game.SoundService.Songs.Stage2.Playing = false
end

function playSong2(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    if Player then
        game.ReplicatedStorage.RemoteEvent:FireClient(Player)
    end
end

playSong1()
workspace.Checkpoints.Stage2.Touched:Connect(playSong2)
--Client (Insert a LocalScript and put in StarterPlayerScripts!)
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
	game.SoundService.Songs.Stage1.Playing = false
	game.SoundService.Songs.Stage2.Playing = true
end)
1 Like

Thanks, this is exactly what I missed out on, and I couldn’t figure it out.

1 Like

Yeah anytime! There’s always those hidden nitpicky objects we just can’t find :sweat_smile: So you’re all good

1 Like