How would I shutdown a server using a script?

I’m trying to make a script that shuts down servers, removing all players and preventing anyone from joining that server.

First I tried to just kick every player ingame, but the server was still up after that and players could still join that server.
I tried to kick anyone who joins the server, but again the server was still up, basically softlocking the game and kicking anyone who joins and not creating any new server.

Is there a built in method to shutdown servers similar to the way you can from the website?
If not, is there a way to change the max players of a server so I can just change that to 0 after kicking everyone?


i dont think there is any built-in shutdown method, so kicking players is the only option.

instead of kicking every player only once, you should kick every player continuously instead of only once. the easiest way would to do this on a server script:

while wait() do
	for _, player in pairs(game.Players:GetChildren() do

and after the server is empty for a bit of time, the server will automatically shut down.

1 Like

Bind the kick to a PlayerAdded function:

local locked = false
local function shutdown(): ()
	for _, player in pairs(game.Players:GetPlayers()) do
		player:Kick("Server Shutdown!")
	locked = true

	if locked then
		player:Kick("The server is locked!")
	--your actual player added code

Even though the server is kicking people when the join, the server is still up. With a small game like the one I’m working on, that’s frequently the only server up, and since there’s already an open server Roblox doesn’t make a new one, effectively softlocking the game and kicking everyone who joins.

You can try going berserk and crashing the server afterwards by filling the memory on the server-side. That way it won’t be able to handle join requests and it will eventually shutdown by Roblox. Hacky solution but most likely works. Just ensure that before doing that all player data is saved, all necessary operations done, etc.