game:BindToClose() failing when I attempt to use it

I’ve been using this function for quite a while with no issues whatsoever until today.

When I fire BindToClose, it fails with this error in output:
image

I’ve searched the forums and only found one post with the same issue, however it was from years ago and had no responses. I’ve attempted to fix this by using it in a different script and have also made sure it’s only being used in one script at a time.

Example code:

game:BindToClose(function ()
    --Do some stuff.
    wait(1) --Allow stuff to finish before closing.
end)
1 Like

It looks like you’re trying to close the game when the game is closing? I think you should be binding it when the server starts.

Otherwise it works perfectly fine for me. I put some code in a Script in ServerScriptService and it looked like it worked.

game:BindToClose(function()
	print"noo dont close! not yet D:!!"
	wait(5)
end)