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
Player:Kick(tostring(message))
end
end
shutdown("shutdown message")
**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.
1 comment
You destroyed the closure of the v:Kick. This would error.