I don't know much of scripting, and I've been having some troubles figuring this out. I've been trying to make the background music change to a different audio once a specific player joins the game, and the music returns back to the original audio once the player leaves. I've seen questions similar to this on this website before, but not exactly what I'm looking for. May I have some help?
COMMUNITY QUESTION
How can I change the background music once a specific player joins the game?
2 answers
You can use Players service's PlayerAdded event on a server script. Something like:
local Sound = (sound here);
game:GetService("Players").PlayerAdded:Connect(function(plr)
if plr.Name ~= "player here" then return; end
Sound:Stop();
Sound.SoundId = "id here";
Sound:Play();
end)
EDIT: Fixed dumb space :)
Hello,
You should put this code in a Server Script. Remember to use the Player ID and Sound ID. Otherwise it will not work.
local Sound = Instance.new("Sound")
Sound.Parent = game.Workspace
game:GetService("Players").PlayerAdded:Connect(function(player)
if player.UserId == "PLAYERID" then
Sound:Stop();
Sound.SoundId = "rbxassetid://20912039"; -- Change ID to whatever sound you want to play when that player joins
Sound:Play();
else end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
Doesn't seem to be working, what do I put in "sound here"? And don't you put the player's name in "player here", or the ID?
"player here" is the player's name you want. If you want the ID, you can change to plr.UserId ~= "(id goes here)". In the "sound here" you put the reference to the sound instance. If you want you can do Instance.new("Sound").
You should always be using the UserId. It is a static UID. The Player's Name can be changed at their leisure, which makes it an unreliable affirmation.
I've did what you said, nothing worked. I messed around a few things, and still didn't work. I seriously have no idea what I'm doing wrong.
Check the new awnser then