This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shutdown
63 lines (56 loc) · 1.89 KB
/
Shutdown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--[[
SoftShutdown 1.3b
Author: Merely
Editor: Jerse;
This system lets you shut down servers without losing a bunch of players.
When game.OnClose is called, the script teleports everyone in the server
into a reserved server.
When the reserved servers start up, they wait a few seconds, and then
send everyone back into the main place.
--]]
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", workspace)
m.Text = "This is a temporary lobby. Teleporting back in a moment."
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
function Shutdown(Values)
if (#Players:GetPlayers() == 0) then
return;
end;
if (game:GetService("RunService"):IsStudio()) then
return;
end;
local m = Instance.new("Message", workspace)
m.Text = "Rebooting Servers " .. Values["Reason"]..". Shortly you'll be teleported back.";
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
end
game:BindToClose(function()
Shutdown({
Reason = "For in-game Updates"; --// Can be changed. The reason for shutdown when game.OnClose is called;
})
end);
end
------ Scripted by Jerse ------