Make a sound when you leave?

Hi, well, I’ve been trying to add a small detail to my game and it is that when leaving the game it makes a noise like Bye or something, is something like that possible?

8 Likes

I haven’t come across anything like that yet
But the idea is good
If when you exit the game, you can make an inscription in the chat
You can also add sound

4 Likes

Here:


-- First, create a sound object using the "Sound" service

local Sound = Instance.new("Sound")

Sound.SoundId = "rbxassetid://[INSERT SOUND ID HERE]" -- Replace [INSERT SOUND ID HERE] with the ID of the sound you want to play

Sound.Volume = 1 -- Adjust the volume as needed

-- Next, connect to the "PlayerRemoving" event to detect when a player leaves the game

game.Players.PlayerRemoving:Connect(function(Player)

-- Finally, play the sound effect when the player leaves the game

Sound:Play()

end)

2 Likes

Hey, you should add this to your code so the sound’s parent isn’t nil.

local Sound = Instance.new("Sound", workspace) -- You can change this to whatever you'd like. Just don't put it inside of a part.
3 Likes

And where should I put this? I mean in scriptservice or where?

1 Like

It would be better to do this in a local script, also need to check the player leaving is the local player.

players.PlayerRemoving:Connect(function(player)
  if player == players.LocalPlayer then
    --play sound
  end
end

I don’t believe parenting it to workspace makes a difference

And where would this have to be, that is, in some specific place?

StarterPlayerScripts should be fine

Ok I did all but it doesn’t seem to work :frowning:

apparently it doesn’t work I saw if there were errors but nothing comes out :frowning:

Did you scroll? I clearly stated that they could parent it to whatever they wanted, just as long as it wasn’t inside of a part.

I’m not sure if this works.
First, put a sound in soundservice and then a local script in starter player scripts

local sound = game.SoundService.yoursound

game.Players.PlayerRemoving:Connect(function(plr)
if plr == game.Players.LocalPlayer then
sound:Play()
end
end)
1 Like

Greetings MrAge,

To do this you can create a server script, and place it either in workspace or ServerScriptService:

local DB = game:GetService("Debris") --debris is a service that deletes something after a given amount of time

game.Players.PlayerRemoving:Connect(function(plr)
local Character = plr.Character
local Root = Character.HumanoidRootPart

local Sound = Instance.new("Sound") --we create the sound and change its properties
Sound.SoundId = "soundidhere"
Sound.Volume = 0.5 --or whatever you want

local Part = Instance.new("Part") --here we create a part, where we place the sound for a directional effect
Part.Transparency = 1
Part.CanCollide = false
Part.Anchored = true
Part.Parent = workspace
Part.Position = Root.Position

Sound.Parent = Part
Sound:Play()

DB:AddItem(Part, Sound.TimeLength) --clean up the part after the sound plays
end)

Hope this helps!

Hmm, I would set the sound to play on remove or something. Maybe make a local sound that plays when the player leaves? I wouldn’t make it a server script since it would play for everyone in the game.

Well, I tried and that didn’t work either, if something that I forgot to mention is that my game is single player so it is necessary that only you listen to it (and sorry for replying a bit late)

Do you want the sound to play for everyone or locally?

sorry, i dont know whether that’s possible. but you can make a button that kicks the player, and before doing so it plays the sound effect.

local vol = 6.9 -- volume
local id = "rbxassetid://420666"

-- rest of code
local part = Instance.new("Part")
part.Parent = game.Workspace
part.Transparency = 1
part.CanCollide = false

local sound = Instance.new("Sound")
sound.SoundId = id
sound.Volume = vol
sound.PlayOnRemove = true

I think sounds can play when the player leaves and PlayOnRemove is turned on.

yeah that was my second option but hey thanks for the help

oh…and how is this supposed to work?