BindToClose (and TeleportService?) not functioning properly

In the past, we have been able to use TeleportService in conjunction with BindToClose to teleport our players to a reserved server lobby while we perform game updates (such as with Merely’s soft shutdown script), which allows us to keep the vast majority of our concurrent players after we shutdown our games for updates.

As of yesterday (or the day before?) it instead instantly shuts down the server, preventing us from teleporting any players. It may even be entirely an issue with BindToClose as it doesn’t seem to yield and show the initial warning message that it usually does.

This functionality is super important to a lot of games and I’d hate to lose it!

3 Likes

I’ve been having problems with this as well recently, I thought I made a script error or something while working with datastores but now I am not even sure. If it doesn’t yield then that explains why sometimes data doesn’t save while shutting down the server.

I have also been having issues with BindToClose. In PlaySolo it no longer yields for DataStores and requires me to put a manual wait time at the end of BindToClose to ensure it does actually perform saving etc.

Thank you for bringing this to our attention! We made a change in “Shut Down All Servers” that (unintentionally) disconnected all users from the game before BindToClose callbacks were being invoked. We just disabled that change and will fix the underlying issue before re-enabling.

@wravager this fix likely won’t affect the issue you are seeing in studio, we will follow up with your issue.

3 Likes

Can you please post a minimal code snippet demonstrating the problem?
Like

  • here’s the code.
  • here’s what I expect to happen.
  • here’s what actually happens.

Thanks

server.save = function(userId)
     do datastore saving here
end

game:BindToClose(function()
	for i,v in pairs(data)do
              server.save(i)
        end
end)

In PlaySolo BindToClose requires this to complete the saving which doesn’t make sense to me.

game:BindToClose(function()
	for i,v in pairs(data)do
        server.save(i)
    end
    wait(1)
end)

Thanks.
Could I request an even more specific example?
In the code provided, “data” isn’t declared, and “do datastore saving” isn’t really code.
I was hoping for a script I could just run as-is to demonstrate the problem.
The datastore saving could be “dummy” data, just writing out random strings or whatever.

code
local data 		= {}
local server 	= {}

local service	= game:GetService('DataStoreService')
local store		= service:GetDataStore('data')
local http		= game:GetService('HttpService')

server.save = function(userId)
	
	if(data[userId])then
		local userdata = http:JSONEncode(data[userId])
		local success, failure = pcall(function()
			print'save'
			store:SetAsync(userId, userdata)
		end)
	end
	
end

game.Players.PlayerAdded:connect(function(player)
	
	data[player.userId] = {}
	
end)

game:BindToClose(function()
		
	for i, v in pairs(data)do
		server.save(i)
	end
			
end)

Thanks.

We tried that code on a production build and did not experience the problem you’re describing.

Can you confirm you are seeing this with latest production build (345)?

Merely’s soft shutdown is working again, so I think it is fixed.

I believe it’s happening again. (9/18/2021)

Please file a new, descriptive bug report for new issues