How do I restart the server and make all players reconnect?

Hello, noob coder here that can only change variables n blocks cuz I only know Java basics.

I made a Nuclear-Reactor “game” which source I want to publish for builders to use. Once the reactor reaches a certain point it’s meant to explode, expand, kill players near it then give them a black screen and then reset the server after a certain amount of time.

I’ve only kinda managed to implement the expanding dome that kills players, GUI 2 hard, but that’s not what I am here for.

As mentioned I want to restart the server after a set amount of time. That means it reloads everything and reconnects the players like alot of other games do. But I have no idea how to.

Is there an easy way to do this with a script inside a workspace folder? Or am I just better off kicking all players?

2 Likes

You can use the teleport service to reserve a new server and move all the players into that new server.

The current server will then need to be shut down. (Automatically happens when there are no players), You can set player cap on that server so that nobody can join it.

4 Likes

I found a script that should do that, however it aways gives me the error
Player1 is not a valid member of Players “Players” - Server - MasterScript:174

Here’s the script:

local placeId = 6050694511
local playersList = {
	game:GetService('Players').Player1,
	game:GetService('Players').Player2
}

game:GetService('TeleportService'):TeleportPartyAsync(placeId, playersList)
1 Like

You can just replace the 2nd-5th line with local playersList = game:GetService("Players"):GetPlayers() if you want to teleport all players.

2 Likes

I’m making progress but now it says
TeleportService:TeleportPartyAsync error: The player[153619938] with wrong session.
Is this because I am in Roblox Studio?

1 Like

Yes, TeleportService functions doesn’t work if you’re on studio.
Publish it to a Roblox game and try it there.

2 Likes

“Roblox has shut down the server for maintainence, please try again”

Well uhhhh it says you load into the game but then it says this and reconnecting dosen’t work

Place this at the time you would like to reset the server, change the place id to your game it should teleport them back to the game creating a new server or going into another server.

local ts = game:GetService('TeleportService')
for i,v in next,game.Players:GetChildren() do
ts:Teleport(0, v)
end
3 Likes

On a function connected to BindToClose, you can either teleport players to another place of the same game (that’s empty like a baseplate) which is easier imo than reserving a server of the same game and having to filter out things you don’t want to happen in the reserved server. I suggest going with the separate empty place method. Continuing, if you did that, you can leave the loading screen UI in StarterGui (so people don’t see the baseplate) and overwrite RbxCharacterSounds so that you can’t hear any sounds like walking or falling. Make sure the UI in StarterGui is the exact same as the loading screen you teleport with from the main game if you’re using one, so that the transition between games is seamless and you can’t tell. So after you have that set up, use a script in ServerScriptService and do a simple PlayerAdded event that just waits for a set amount of time (10 seconds is good to make sure all the servers clear), and then teleport them back to the main game place.

This is basically the structure of how to do it, so after you have this working you can move on to extra stuff like UI tweens.

1 Like

ye i think something like please wait server,
for server shutdown is good but to check if server is available maybe you should make a api.
so when your game runs your api should toggle status to on,
then the server teleports players to the new one.

2 Likes

I found one that works here on the devforum, so here it is

4 Likes

I had already seen that yesterday but it confused me a bit, main reason is it executes once the server shuts down which is something you apperently can’t do automatically but only manually as creator of the game

So I “modified” it and ripped out the “important” code out of the function to run when the script is working, then disabled the script and told my main script to enable it again once the server is supposed to restart

Thanks alot to everyone who posted here (even if I didn’t use all of them), without them I’d still be at square one!

1 Like