Music not playing on game shutdown

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)

Any suggestions?

3 Likes

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.

Is the music by Roblox?
Are you sure, you added the id you want?
Check Volume by the way.

2 Likes

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.

1 Like

He plays it 3 seconds before shutting down

2 Likes

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.

The Universe ID can be found here:

3 Likes

Make sure to check the properties of the sound itself.

1 Like

Try putting that out? Maybe you deleted your sound?

1 Like

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.

2 Likes

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

Tried many ways. My answer is … You can’t !!

1 Like
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)
3 Likes

I added the sound into the game instead of playing it on shutdown and it worked. Thank you for your answers though.

1 Like

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