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?
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)