Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Shutdown Server Script? [closed]

Asked by 9 years ago

This is harder than it seems. I tried while true do end and doesn't work. It only slows down the game. When I try to do game:remove() or NetworkService:remove(), it is locked. I know it is possible from the 2013 Hallow's Eve (I think that's what it was called) and whenever there was an update there was a countdown and when it reached 0 all servers shut down so the updates could take effect. I need to know this!

Do not suggest these:

while true do end game:remove()

They do NOT work.

Locked by BSIncorporated, MessorAdmin, TheeDeathCaster, and TurboFusion

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
1
Answered by 9 years ago
for i,v in ipairs( game.Players:GetPlayers() ) do
    coroutine.resume(coroutine.create(function()
        v:Kick() -- removes all player's by shuting there client down.
    end))
end
Ad
Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

Unfortunately, ROBLOX took out all the fun with shutdown server techniques. You can no longer like, while true do and add onto a string value (Kohl's Admin), or insert a joint thing that was unstable and caused the server to crash (ROBLOX Error Console). The only way you can shutdown a server now, is by kicking all players in a loop like so;

while wait() do --Continually loops
    for _,v in pairs(game.Players:GetChildren()) do --Gets a table of all players and goes through it.
        v:Kick() --Kicks the player.
    end
end

or you can do a disconnect through a RemoteEvent/RemoteFunction, with a Local script in StarterPack saying this (you might not even need it);

game.ReplicatedStorage.sd.OnServerEvent:connect(function() end) --If the event is fired, then this script should be listening.

and a server script with this code

Instance.new('RemoteEvent',game.ReplicatedStorage).Name = 'sd'
game.ReplicatedStorage.sd:FireAllClients(string.rep('a',30000)) --This will just send a string that is 30000 characters big, which 20000 is the minimum before being DC'ed from the server.
Log in to vote
1
Answered by 9 years ago

There are multiple ways of doing this, but, I shall only list two, since these are commonly used (as it appears).

Many use the for loop to kick a Player from the Server, as it (to me) would look some-what like this;

for i,v in pairs(game.Players:GetPlayers()) do
    v:Destroy()
end

One I do is use the PlayerAdded event to prevent a Player from joining the Server. This is how it would look like;

local slock = false; --Variable 'slock' will allow the Player to either join or not; If false, Player can join, if true, Player can not join

function PlayerJoined(plr) --This is the function we will use to prevent a Player from joining
    if slock and not (plr.userId == game.CreatorId or plr.Name:sub(1,6) == "Player") then --This is the 'if' statement; The 'if' statement is used to check if a Condition is equal to the Argument; The 'if' statement is checking if 'slock' is true, and if the Player's userId property is not equal to the Creator's userId, or if the Player's first 6 Characters is 'Player'; If so, then the 'if' statement returns true, if not, then it will not kick the Player
        plr:Destroy() --This will remove the Player from the Server
    end --This ends the 'if' statement chunk
end --This ends the functions chunk

game.Players.PlayerAdded:connect(PlayerJoined) --Now, whenever a Player joins, he/she will not being to join at all; The 'PlayerAdded' event fires when a Player joins the Server

Either way, I recommend using both. :)

Information left out:

1. The if statement is used to check if a Condition is equal to the Argument, or if it returns true.

2. The for loop is used to, well, loop through a Table (a specific, or certain Table), as for example, creating a new table local tbl = {1,2,3};, then setting up the for loop for i,v in pairs(tbl) do print(v) end, will result in the currently Table position being iterated through (in this table) will print into the Output.

3. The GetPlayer method creates a new table of the current Children within the Players service of game (or, as .lua calls it, DataModel).

Hope this helped!