Code to shut down current instance


My game is being exploited and I want to kill the server every 2-3 hours so broken games don’t accumulate.

What Lua code could I use to accomplish this?

Old discussion with no resolution - Unlock :Shutdown()


Simply kicking all players should do it.

local Players = game:GetService("Players")

for i,v of ipairs(Players:GetPlayers()) do

Nah that doesn’t work because I can’t prevent new players from joining and those players constantly trying to enter keep Roblox from killing the server.


With os.time, you can probably check if 2 hours every so often (like once per 30 minutes) if 3 hours (meaning 10800) have passed since the last time os.time was recorded.

Then you could connect to the PlayerAdded function and kick any new players.

local Players = game:GetService("Players")

for i,v of ipairs(Players:GetPlayers()) do


If you kick all players, and no player joined at the time everybody was kicked, that’s rare to happen due to roblox routing joining players to less crowded servers, the server should instantly shutdown, and any mess that was made is gone.

By shutting down an instance you mean the same way you can from the website, where all clients are disconnected and the instance is removed from matchmaking to ensure closure? Can’t do that.

There’s no native API that you can use in game to shut down an instance. While hypothetically you can kick all players to pseudoclose the instance, it will not be removed from automatic matchmaking so new players will still be able to join those servers.

You can make use of ReservedServers to cleverly reroute players if that has any significant effect. For the current instance, when a closure is called, flip on a flag (can just a boolean variable in a script) that identifies the server as “should close”. From there, teleport current players to that reserved server as well as all new players. You can put them back into public servers after some time to filter them back into automatic matchmaking just by a regular teleport to game.PlaceId.

I am unsure why you would do this instead of fixing/limiting the exploit in your game. You are not solving anything by having a server shutdown after 2/3 hours and this will impact your whole playerbase.

I really urge you to review the benafit vs impact this will have.

You could technically do your own server management using reserved servers. When players initially join the game, they’re teleported to a reserved server. You’d need to host a web API to keep track of your servers and manage them, but you’d get full control over which servers exist and which servers players can join.

The downside is that players won’t be able to join specific servers from the website, and you’ll have to manually route players that are following others into games into the correct server.

However, this seems like a band-aid solution to a band-aid solution. Shutting down servers regularly in the first place doesn’t prevent exploiters from taking over a server, and doesn’t prevent them from creating a new broken server. If they’re able to break the game, it’s not necessarily a good idea to assume they can’t just break it again within a few minutes just because their old server closed.

It might be worth taking a close look at your game and seeing what players are doing and patching individual exploits. For example, looking through the game, I found a long list of unanchored parts that really should be anchored. Players moving these parts to places they shouldn’t be relies on them being able to replicate a new position to the server, but as far as I’m aware, the server discards physics replication packets for anchored parts (if it doesn’t, it should!).

It may be good to know in what ways exploiters are breaking your game and attacking their methods. Shutting down the server regularly unfortunately won’t help much.