Sound when leaving the game

Hello robloxians!

I’m trying to make a sound that plays when player leaves the game similarly to how it is in pressure where you can hear sebastians say “Bye!” when leaving the game.

My Current local script looks like:

local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local SoundIDs = { – sound IDs
114060100371339, – Goodbye!
73950896903521, – Byeee!
132010216556223, – Bye in another language
82159782124722, – Cya
79182262330526, – GGs
120683410406490
}
Players.PlayerRemoving:Connect(function(PlayerR)
if PlayerR == Player then
print(“Goodbye!”)
local Bye = SoundIDs[math.random(1,#SoundIDs)] – Random ID from the list
script.Sound.SoundId = Bye
script.Sound:Play()
end
end)

But it doesn’t work and I’d be glad to get some help on that.
I also could not find any models in the toolbox that would do this so went to the forum!
Further help is appreciated

1 Like

I think you should be able to set the sound’s PlayOnRemove value to true, let me know if that solves it.

this is kinda tricky as during player removing the client is removed and the roblox session is terminated on their end, meaning they might not be able to hear the audio in time before the client is shut. player removing should be mostly used to handle things on the server like saving data and not so much as playing audio

1 Like

Tried it and it didn’t work, gave me the same result of nothing but printing out the print

Thanks a lot! It actually worked, I should probably look more into all of the functions object “game” has. Thanks.

its a datamodel not an object in standart roblox terms

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.