I have made a script that handles when the game shuts down. It all works fine except it does not play the shutdown music.
Script in question:
game:BindToClose(function()
script.Parent.Parent.ShutdownMusic:Play()
wait(3)
local msg = Instance.new("Message", workspace)
msg.Text = "THE GAME IS CURRENTLY SHUTTING DOWN."
game.Debris:AddItem(msg, 3)
wait(3)
local msg2 = Instance.new("Message", workspace)
msg2.Text = "This is almost definitely due to a game update."
game.Debris:AddItem(msg2, 3)
wait(3)
local msg3 = Instance.new("Message", workspace)
msg3.Text = "Please rejoin after you get kicked from the server shutdown."
game.Debris:AddItem(msg3, 3)
wait(3)
local msg4 = Instance.new("Message", workspace)
msg4.Text = "Thank you."
game.Debris:AddItem(msg4, 3)
wait(4)
end)
How could you play music on close? Aren’t you getting kicked when game is shutdowned or when player leaves? Basically when you get kicked from a experience, everything stops in your game for that client and it removes every script or sound effect for that player. You can’t.
You can’t play music after you got kicked from the game because when you get kicked roblox removing everything about you. It may work if you kick after playing music but i don’t think so.
Sound.PlayOnRemove = true and Sound.Looped = true, with Sound being the instance. When the game.BindToClose is called, make sure to :Destroy() the Sound instance.
For example,
game:BindToClose(function()
local music = Instance.new("Sound", workspace)
music.SoundId = "rbxassetid://9046476113"
music.Looped = true
music.PlayOnRemove = true
music:Destroy()
end)
When you added the instance, you need to use an Id either on the marketplace or authorized by you. Make sure to hit Save Changes afterwards.
When the Sound is destroyed, the sound plays. It prevents the game from stopping it when it is played normally due to how it’s already destroyed but still playing for players.
I can’t even get that to work on BindToClose … How did you get that far? …
local messages = {
"THE GAME IS CURRENTLY SHUTTING DOWN.",
"This is almost definitely due to a game update.",
"Please rejoin after you get kicked from the server shutdown.",
"Thank you."
}
for _, text in ipairs(messages) do
local msg = Instance.new("Message")
msg.Text = text
msg.Parent = workspace
game.Debris:AddItem(msg, 3)
task.wait(3)
end
game:BindToClose(function()
local music = Instance.new("Sound", workspace)
music.SoundId = "rbxassetid://9046476113"
music.Looped = true
music.PlayOnRemove = true
music:Destroy()
wait(3)
local msg = Instance.new("Message", workspace)
msg.Text = "THE GAME IS CURRENTLY SHUTTING DOWN."
game.Debris:AddItem(msg, 3)
wait(3)
local msg2 = Instance.new("Message", workspace)
msg2.Text = "This is almost definitely due to a game update."
game.Debris:AddItem(msg2, 3)
wait(3)
local msg3 = Instance.new("Message", workspace)
msg3.Text = "Please rejoin after you get kicked from the server shutdown."
game.Debris:AddItem(msg3, 3)
wait(3)
local msg4 = Instance.new("Message", workspace)
msg4.Text = "Thank you."
game.Debris:AddItem(msg4, 3)
wait(4)
end)