How to make a player Rejoin the game?

Hey, so I’m working on DataStores and I was instructed that instead of kicking the player when data doesn’t load, I should have them rejoin the game. I assumed it’d just be with: TeleportService:Teleport(gameID, player)

But whenever I try that, it’ll rejoin the game, but after it rejoins, it brings up a prompt saying “Roblox has shutdown the server for maintenance. Please try again”

Should I be using something else?

Any help would be much appreciated! :slight_smile:

11 Likes

I forgot that Roblox does that, strangely, when you try to teleport a player to the PlaceId of the place you’re currently playing.

You can follow the soft shutdown paradigm by teleporting a player to a reserved server, wait some time (max 30 seconds) and then send the player back to a main server (teleporting back without the reserved server code).

4 Likes

So it’s sort of like a middleman place? So if data fails to load, I teleport to that place, then wait 10 seconds, then teleport them back to the actual place they tried to play?

I don’t think you need to go through the step of teleporting into a reserved server, You can just do:

TeleportService:Teleport(game.PlaceId,plr)
2 Likes

As I said in the original post, doing so causes an error after you rejoin.

1 Like

Well, It only does that because you were the only player in there, You don’t teleport that fast so the server shuts down before you can get in.

3 Likes

Yep, exactly. Try that out and see how it fairs for you.

@ObscureBrandon

While the cause for the message may be that Roblox closed the server due to a zero player count and all closed events finishing, doesn’t mean the code you proposed still works. This still needs to account for empty and full servers. OP already explained that teleporting them back in results in a server closure issue.

You also have no control over how fast a teleport happens, so, can’t do much there.

Assuming that everything that everyone has said up til now is true.

I’m about 100% sure you can get the current player count as well as the MaxPlayer count. So if you think you can’t account for empty and full servers at that point… :thinking: Hmm.

Leaving a server with a zero player count will indeed shut it down. And you indeed don’t have any control over how fast a teleport happens. But if you were the last player in a server, simply teleport them to another server. Only time this won’t work is if you have the place set to a maximum of one player.

2 Likes

Using which TeleportService?

Combined with MessagingService to get a JobID of a valid server.

I sit here scratching my head as I am still confused…
Could you elaborate a bit more? Or give a code example?

I’ve never used the services :sob: So this is just a use case based on the capabilities of the services.

But in the event that the server you’re currently in having more than x amount of players (or 1) you can take @colbert2677 's advice and teleport the player to a reserved server and then back to the main server.

Otherwise you can request another server VIA the MessagingService and get the JobID of a valid server that has more than x amount of players and teleport them there instead.

1 Like

Maybe this will help u

local TeleportService = game:GetService("TeleportService")

local Player = Player -- path to player
local reserveCode = TeleportService:ReserveServer(game.PlaceId)

TeleportService:TeleportToPrivateServer(game.PlaceId, reserveCode, { Player })
7 Likes

I attempted that earlier and got a weird error. I’ll mess with it a bit more later and reply back if I get the same error.
Thanks for posting. :slight_smile:

Merely actually made a soft shutdown script that you can add into your game.

4 Likes

thank you for your help i have been trying to figure this out for a long time