BindToClose not working for me?

Ok, so I made a shutdown script and to test it I shut down the VIP server im in. (I want to make sure it properly shuts down for everyone when a update comes out.)

However it does not stop at all and kicks me…

Code:

game:BindToClose(function()
	print("shutting down")
	game.Workspace.BoxStormSiren.Volume = 1
	game.Workspace.BoxStormSiren:Play()
	game.ReplicatedStorage.GameClosing:FireAllClients()
	for i,plr in pairs(game.Players:GetChildren()) do
		DataStore2.SaveAll(plr)
	end
	wait(15)
	print("Shutdown complete..")
end)

Am I just being really stupid or what?

As far as I know BindToClose is called when the server is shutting down and kicks everyone regardless if you want to or not so think of it like enabling a script when the server is shutting down.

1 Like

You are allowed to delay it for 30 seconds as seen here: https://developer.roblox.com/en-us/api-reference/function/DataModel/BindToClose

I’d try the exact code snippet from the post you linked. If that doesn’t work as intended, it might be worth filing a bug report.

Yes that’s the point of BindToClose. It doesn’t allow you to continue playing during this time, it is used to run a set of functions before the instance is closed so you can do any last-minute cleaning.

Oh, I thought you where allowed to delay the players leaving.