BindToClose won't work

Hey. I scripted my small soft shutdown script but the problem is: the BindToClose function won’ work good. I mean with that, the UI is like getting enabled but not even a milisecond after this, I get disconnected as the developer have shutted the server down. My small code is:

if not RunService:IsStudio() then
	game:BindToClose(function()
		wait(2)
		local reservedServer = tpServer:ReserveServer(game.PlaceId)
		for i,v in pairs(game.Players:GetPlayers()) do
			if v:FindFirstChild("PlayerGui") then
				v.PlayerGui.Shutdown.Enabled = true
				v.PlayerGui.Shutdown.ShutdownServer.Visible = true
				tpServer:TeleportToPrivateServer(game.PlaceId,reservedServer,v)
			end
		end
	end)
end

Video how it looks like:

I would appreciate it greatly if someone could help me at this problem. xd

Is this defined as TeleportService?

Yes, it is. tpServer is defined as the Teleport Servied given by Roblox.

if u are using the shutdown all servers button from the site, this script wont work. I recommend making some sort of Version checker rather than making it manual. If the version is different from the current one then just move all the player to the new server.

Hm? The problem is that the server is kicking automaticlly everyone via the basic Roblox System but I don’t this. H ow to disable this?

I dont think u can disable that

Alr. Then how to bypass it so people DON’T get kicked via the basic roblox system?

hmmm Im not really sure. Maybe if u somehow queue the players wait for the shutdown to happen and then teleport them to the game. That can happen using other game for teleporting

Have you ever scripted? BindToClose is saying the game: Wait before shutting down and kicking all players. It’s doing that but somehow the game is still kicking everyone after a second.

I’ve scripted something similar, but using different method.
https://www.roblox.com/library/8164243100/ForceGameUpdate
this one doesn’t use BindToClose

Hm. So you really don’t know how to do it with BindToClose?

Not really. I dont use BindToClose

if not RunService:IsStudio() then

What do you mean with that? I mean, I have already pasted it into my script-

That means that portion of the script won’t execute while in studio.

Oh yea ofc. I do tthe tests in the game itselfs on Roblox. Not in Roblox Studio.

Well I see the issue, “TeleportToPrivateServer()” needs to be passed an array of player instances not individual player instances.

Something like this.

if not RunService:IsStudio() then
	game:BindToClose(function()
		local reservedServer = tpServer:ReserveServer(game.PlaceId)
		tpServer:TeleportToPrivateServer(game.PlaceId, reservedServer, game.Players:GetPlayers())
	end)
end

https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportToPrivateServer

Oh alright! I think this is solving my problem. I will try it out and tell you if it’s working or not. ^^

I’d recommend utilizing game.JobId first, then use game:BindToClose. Something like this:

if not RunService:IsStudio() then
	local reservedServer = tpServer:ReserveServer(game.PlaceId)

	if game.JobId == "" then
		task.wait(2)
		for i,v in pairs(game.Players:GetPlayers()) do
			if v:FindFirstChild("PlayerGui") then
				v.PlayerGui.Shutdown.Enabled = true
				v.PlayerGui.Shutdown.ShutdownServer.Visible = true
				tpServer:TeleportToPrivateServer(game.PlaceId,reservedServer,v)
			end
		end

        game:BindToClose(function()
            if #game.Players:GetPlayers() > 0 then
                for Index, Player in ipairs(game.Players:GetPlayers()) do
                  v.PlayerGui.Shutdown.Enabled = true
		          v.PlayerGui.Shutdown.ShutdownServer.Visible = true
		          tpServer:TeleportToPrivateServer(game.PlaceId,reservedServer,v)
               end
            end
        end)
	end
end

I believe this would work, let me know if I did anything wrong!

1 Like

Nw! I think your script would work too but I used the method stated above but still thank you for your work and time into this script! Thank you so much. <3

1 Like