local L=game:GetService("\084\101\108\101\112\111\114\116\083\101\114\118\105\099\101")local w=game:GetService("\080\108\097\121\101\114\115")if game.VIPServerId~=""and game.VIPServerOwnerId==0 then local s=Instance.new("\077\101\115\115\097\103\101")s.Text="\084\104\105\115 \105\115 \097 \116\101\109\112\111\114\097\114\121 \108\111\098\098\121\046 \084\101\108\101\112\111\114\116\105\110\103 \098\097\099\107 \105\110 \097 \109\111\109\101\110\116\046"s.Parent=workspace local F=5 w.PlayerAdded:connect(function(w)wait(F)F=F/2 L:Teleport(game.PlaceId,w)end)for w,s in pairs(w:GetPlayers())do L:Teleport(game.PlaceId,s)wait(F)F=F/2 end else game:BindToClose(function()if#w:GetPlayers()==0 then return end if game.JobId==""then return end local s=require(game.ServerScriptService.MainModule)for L,w in pairs(w:GetPlayers())do local F=(s("\083\116\097\116\115",w)):Get();(s("\083\116\097\116\115",w)):Update(function(L)return F end)end local F=Instance.new("\077\101\115\115\097\103\101")F.Text="\082\101\098\111\111\116\105\110\103 \115\101\114\118\101\114\115 \102\111\114 \117\112\100\097\116\101\046 \080\108\101\097\115\101 \119\097\105\116"F.Parent=workspace wait(2)local m=L:ReserveServer(game.PlaceId)for w,s in pairs(w:GetPlayers())do L:TeleportToPrivateServer(game.PlaceId,m,{s})end w.PlayerAdded:connect(function(w)L:TeleportToPrivateServer(game.PlaceId,m,{w})end)while#w:GetPlayers()>0 do wait(1)end end)end


local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

if (game.VIPServerId ~= "" and game.VIPServerOwnerId == 0) then
	-- this is a reserved server without a VIP server owner
	local m = Instance.new("Message")
	m.Text = "This is a temporary lobby. Teleporting back in a moment."
	m.Parent = workspace
	
	local waitTime = 5

	Players.PlayerAdded:connect(function(player)
		wait(waitTime)
		waitTime = waitTime / 2
		TeleportService:Teleport(game.PlaceId, player)
	end)
	
	for _,player in pairs(Players:GetPlayers()) do
		TeleportService:Teleport(game.PlaceId, player)
		wait(waitTime)
		waitTime = waitTime / 2
	end
else
	game:BindToClose(function()
		if (#Players:GetPlayers() == 0) then
			return
		end
		
		if (game.JobId == "") then
			-- Offline
			return
		end
		
		
		local DataStore2 = require(game.ServerScriptService.MainModule)
		for _,player in pairs(Players:GetPlayers()) do
			local data = DataStore2("Stats",player):Get()
			DataStore2("Stats",player):Update(function(old)
				return data
			end)
		end
		
		
		local m = Instance.new("Message")
		m.Text = "Rebooting servers for update. Please wait"
		m.Parent = workspace
		wait(2)
		local reservedServerCode = TeleportService:ReserveServer(game.PlaceId)
		
		for _,player in pairs(Players:GetPlayers()) do
			TeleportService:TeleportToPrivateServer(game.PlaceId, reservedServerCode, { player })
		end
		Players.PlayerAdded:connect(function(player)
			TeleportService:TeleportToPrivateServer(game.PlaceId, reservedServerCode, { player })
		end)
		while (#Players:GetPlayers() > 0) do
			wait(1)
		end	
		
		-- done
	end)
end
