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

How do I create a message when the game is shutdown?

Asked by 8 years ago

I have tried to make a message when the server is shutdown but it does not seem to work. It is a normal script in workspace.

game.Onclose = function()
    for _,Player in pairs (GetPlayers()) do
        Player:Kick("This server has been shutdown by boogieboon. This is probably due to Updates; try rejoining ASAP.")
        repeat wait() until not Player.Parent
    end
end


2 answers

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
8 years ago

game.Onclose doesn't shut the server down itself, but only executes whatever code it is tasked to execute within a 30 second yielding period. After the code is ran or the yielding period is up, the server then proceeds to shutdown.

Your code snippet would work if you had another function that enforced the shutdown. It wouldn't make much sense, however, because this function essentially does the same thing.

You are now only left with one option, which is creating a function to take care of the shutdown instead of using your current method.


local shutdown = function(message)
    for _, Player in pairs(game.Players:GetPlayers()) do -- loop through players
        Player:Kick(tostring(message)) -- kick, with message being the supplied argument
    end
end

shutdown("shutdown message") -- "shutdown message" will be displayed whenever the
--players get kicked.

Note:you need to find a more practical way of using this concept, because as of now it will initiate the call to shutdown the server as soon as it is created.

Ad
Log in to vote
0
Answered by 8 years ago

Nothing is really wrong, but the repeat is unneeded, and you did GetPlayers() as if there was a function. Try this...

game.OnClose = function()
    for _,v in pairs(game.Players:GetPlayers()) do
        v:Kick("This server has been shutdown by boogieboon. This is probably due to Updates; try rejoining ASAP."
    end
end
0
You destroyed the closure of the v:Kick. This would error. Nickoakz 231 — 8y

Answer this question