Make player rejoin same server?

So I am trying to make it so the player can rejoin when they request a rejoin. Keep in mind I want this to work via server not client. I tried following the instructions on the following link below but it didn’t help.

This was in the game, it’s a public game and it was not a VIP server.

When a player disconnects, you need to store the server they were in to send them back.

You can’t just teleport them to the same server instance anymore?

Not sure, I haven’t worked with TeleportService, if that was a thing, it might still exist, but never knew that was a thing in the first place.

The method you provided was correct, however, it requires a placeId, and I do not see anything about the last server they were on, so you would need to store it manually.

Hey,

I encountered a similar issue and it was due to me using older teleport methods, you’d want to switch to teleportService:TeleportAsync and use a TeleportOptions to specify the target game.JobId (which would be the JobId of this server)

Here’s how I’d implement a rejoin command using TextChatService:

local players = game:GetService('Players')
local teleportService = game:GetService('TeleportService')
local textChatService = game:GetService('TextChatService')

local commands = textChatService:WaitForChild('TextChatCommands')

local rejoinCommand = Instance.new('TextChatCommand')
rejoinCommand.PrimaryAlias = '/rejoin'
rejoinCommand.Parent = commands

rejoinCommand.Triggered:Connect(function(source, text)
	local userId = source.UserId
	
	local player = players:GetPlayerByUserId(userId)
	
	if not player then
		return
	end
	
	local playersCount = #players:GetPlayers()
	
	local teleportOptions
	
	if playersCount > 1 then --[[	we check for the number of players to be greater than 1 
									because when we try joining this server, it will have 
									already been marked as shutting down (we will encounter 
									an inf. load), so we need to teleport them to a new server,
									thus we want to not pass a TeleportOptions so we get the default
									teleporting behaviour.
									
									don't believe there's a way to get around the server shutdown behaviour ]]
		teleportOptions = Instance.new('TeleportOptions')
		teleportOptions.ServerInstanceId = game.JobId
	end

	teleportService:TeleportAsync(game.PlaceId, { player }, teleportOptions)
end)
1 Like

Thank you very much! Glad someone had the answer.

1 Like

Oh, so sorry, I thought you meant if the user left the game then rejoined later, silly me

All good, have a good day bro.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.