Does a good method even exist? Kicking all players still lets other players to join which won't shutdown it. I know that you can just kick every player that joins the server too but i don't like that way.
COMMUNITY QUESTION
How do i shutdown a server?
3 answers
All you have to do is go on your game page, and click the three dots on the top right corner. Then click "shut down all servers".
1 comment
0
I'm making an admin script. I want to shut down in-game.
You could lock the server.
local serverLocked = false
game:GetService('Players').PlayerAdded:Connect(function(plr)
if serverLocked == true then
plr:Kick'Server is shut down!'
end
end)
-- You can add your custom code to lock/unlock the server.
You could use a trigger of some sort (ex: a RemoteEvent could be fired to a script to do this, or anything else you want) and iterate through the players in a for loop to repeatedly kick them until you cancel the "shut down." Example:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function() --This is merely an example, do what you wish for the trigger function!
for i, plr in pairs(game.Players:GetPlayers()) do
plr:Kick("Server shutdown")
end
end)
If you don't want to kick them, you could use :Destroy() if absolutely wanted, but it's not recommended so you could just teleport them to a server/place where they get kicked automatically on joining.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
You would want to teleport the players not kick them.
https://scriptinghelpers.org/questions/336/best-way-to-shutdown-a-server