Is there a way to make sure empty servers clear all data?

I’m making a single player game, and many scripts in the game won’t function properly if a player joins a server that still has old info from previous use. The max player count is set to 1, but I’ve heard servers don’t close immediately upon being empty, and players may join a still-active server. How do I make sure servers completely restart and don’t keep old data?

You could set the player count to 0, or set a counter on the server for when a player joins. Then if the counter is higher than 1 (another player joined) you kick them.

I think you can do this:

game:BindToClose(function()
   game.Players.MaxPlayers = 0
end)

So when the server is about to close, it will set the max player to 0 and no new players would be able to join.

1 Like

I’m not entirely sure but I think this will only work in Roblox Studio but it might work in Live Games aswell.

Try using game:ShutDown(), upon the player leaving the game

game:GetService("Players").PlayerRemoving:Connect(function() -- example
game:ShutDown()
end)

This only works in studio, it won’t work in the servers.

Try and kick the user upon them leaving

Changing the server’s max player would be the best way since if people keep joining after the script kicks a person, the server would never close.

local Debris = game:GetService("Debris")
game:GetService("Players").PlayerAdded:Connect(function(player)
	Debris:AddItem(player, 0)
end)

instantly gets rid of the player

1 Like