[Solved] Rejoin System Not Working

Hello everyone! I’m now developing a game where each round takes a place in other place (like in dead rails), now I’m trying to make a rejoin system when I leave the game when it’s not over.

I’m facing a problem now, describing it below:

When a player is teleported, the game saves in the DataStore the code of the private server that was reserved for the players, as well as the PlaceId where they should be teleported. If a player leaves the game, but the round is not over yet, he can return to the game (the rejoin menu appears), but when you click the rejoin button, the player is not teleported, and an error is displayed:

Here is a part of the script with a reaction to a button click:

Rejoin.OnServerEvent:Connect(function(player, PlaceId, ServerId)
  game:GetService("TeleportService"):TeleportToPrivateServer(PlaceId, ServerId, player)
  print("== TELEPORT REJOIN FIRED")
end)

At first I thought that this problem was related to the fact that IDs are not saved, and I added a print from IDs, and everything was here.

I decided to add a print when entering the round itself, but for some reason an error appears:


(I’ll add the code responsible for this print a little later)

And I decided to add a print again - this time to the part where the player is teleported:

Here is the code for teleporting and saving ID:

Plr:WaitForChild("ServerData").ServerId.Value = TeleportOptions.ReservedServerAccessCode
    local code = TeleportOptions.ReservedServerAccessCode
    print("code " .. Plr:WaitForChild("ServerData").ServerId.Value)
    game.ReplicatedStorage.RejoinEvents.SaveCode:FireClient(Plr, code)

Here is the code for the teleport button

script.Parent.MouseButton1Click:Connect(function()
  local Place = PlaceId.Value
  local Server = ServerId.Value
  print("== REJOIN FIRED")
  game.ReplicatedStorage.RejoinEvents.Rejoin:FireServer(PlaceId, ServerId)
  print("sent")
  script.Parent.Parent.Visible = false
end)

Thanks in advance for your answers :wink:

Hello!
What is the value of Plr variable?

Its a player from the function.

Can you please show the code where it saves the whole TeleportOptions.ReservedServerAccessCode?

If you mean the code for saving the server code then here it is:

local DataStoreService = game:GetService("DataStoreService")
local Data = DataStoreService:GetDataStore("ServerIdData")

game.Players.PlayerAdded:Connect(function(player)
	local playerData = Data:GetAsync(player.UserId)
	if not playerData then
		playerData = {
			ServerId = "",
			PlaceId = 0
		}
		Data:SetAsync(player.UserId, playerData)
	end

	player.ServerData.ServerId.Value = playerData.ServerId
	player.ServerData.PlaceId.Value = playerData.PlaceId

end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerData = {
		ServerId = player.ServerData.ServerId.Value,
		PlaceId = player.ServerData.PlaceId.Value
	}
	Data:SetAsync(player.UserId, playerData)
end)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Rejoin = ReplicatedStorage.RejoinEvents.Rejoin
local Cancel = ReplicatedStorage.RejoinEvents.Cancel

Rejoin.OnServerEvent:Connect(function(player, PlaceId, ServerId)
	game:GetService("TeleportService"):TeleportToPrivateServer(PlaceId, ServerId, player)
	print("== TELEPORT REJOIN FIRED")
end)

Hi, you’re passing an Instance to TeleportToPrivateServer instead of the actual values. That error right there is a perfect giveaway for that reason.

This code:

local Server = ServerId.Value
print("== REJOIN FIRED")
game.ReplicatedStorage.RejoinEvents.Rejoin:FireServer(PlaceId, ServerId)

Notice how you’re firing PlaceId and ServerId (which look like ObjectValues / StringValues / IntValues Instances inside the player), not their values?

So like, when your remoteevent grabs them, PlaceId is literally an Instance (like an IntValue object).
TeleportToPrivateServer expects:
PlaceId which should be a number
ServerId which should be a string (the reserved server code)
Players which should be a table of players, not a single player instance

You should send the values instead of instances, wrap player in a table when tping them, to fix the issue.

You also mentioned this:

This error is most likely because ServerData doesnt exist inside the player yet. You needa make sure you create it when the player joins.

like this?

local rejoinData = {
    Player = 123456789,
    PlaceId = 1234567789,
    ServerId = fnf23893ncal184coqnci1fvb4135jnss
}


Wrap the ServerId in quotes because LuaU will think thats some random variable name.
But yeah, this is acceptable other than ServerId.

thx, i`ll try it tomorrow, hope it will work :folded_hands:

I edited script and now its looking like this:

Rejoin.OnServerEvent:Connect(function(player, PlaceId, ServerId)

  local rejoinData = {
    player1 = player,
    PlaceId1 = PlaceId,
    ServerId1 = ServerId,
  }
  --[[print("player " .. rejoinData.player1)
  print("place-id " .. rejoinData.PlaceId1)
  print("server-id" .. rejoinData.ServerId1)]]--
  game:GetService("TeleportService"):TeleportToPrivateServer(rejoinData.PlaceId1, rejoinData.ServerId1, rejoinData.player1)
  print("== TELEPORT REJOIN FIRED")
end)

But its not working :face_with_diagonal_mouth: (maybe im doing smth wrong?)


in-game error

studio error

i found another error, now tryin to fix it (its not worked)

use ‘ToString()’ to change from instance to string o the script will work

game:GetService("TeleportService"):TeleportToPrivateServer(tostring(rejoinData.PlaceId1), tostring(rejoinData.ServerId1), tostring(rejoinData.player1))

local rejoinData = {
    player1 =  toString (player),
    PlaceId1 = toString (PlaceId),
    ServerId1 = toString (ServerId),
  }

now im getting this (got string, instead of got Instance)
image

local DataStoreService = game:GetService("DataStoreService")
local Data = DataStoreService:GetDataStore("ServerIdData")

local ServerId
local PlaceId
game.Players.PlayerAdded:Connect(function(player)
	local playerData = Data:GetAsync(player.UserId)
	if not playerData then
		playerData = {
			ServerId = "",
			PlaceId = 0
		}
		Data:SetAsync(player.UserId, playerData)
	end

	player.ServerData.ServerId.Value = playerData.ServerId
	player.ServerData.PlaceId.Value = playerData.PlaceId

end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerData = {
		ServerId = player.ServerData.ServerId.Value,
		PlaceId = player.ServerData.PlaceId.Value
	}
	Data:SetAsync(player.UserId, playerData)
end)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Rejoin = ReplicatedStorage.RejoinEvents.Rejoin
local Cancel = ReplicatedStorage.RejoinEvents.Cancel

Rejoin.OnServerEvent:Connect(function(player, PlaceId, ServerId)
	game:GetService("TeleportService"):Teleport(PlaceId,player)
	print("== TELEPORT REJOIN FIRED")
end)

I tried to do this, but it didn’t work because the players are on a private reserved server, not a regular one.

Could you show the full local script? As your problem could be coming from a small mistake there.

Also on the server script when you pass the player value it should be wrapped in curly brackets, As teleport to private server expects a table of players.

Rejoin.OnServerEvent:Connect(function(player, PlaceId, ServerId)
  game:GetService("TeleportService"):TeleportToPrivateServer(PlaceId, ServerId, {player})
  print("== TELEPORT REJOIN FIRED")
end)
    print("== REJOIN REQUEST ==")
    print("From:", player.Name, " | PlaceId:", placeId, " | ServerId:", serverId)

    local TeleportService = game:GetService("TeleportService")

    TeleportService:TeleportToPrivateServer(placeId, serverId, { player })

    print("== TELEPORT REJOIN FIRED")
end)

Sorry, my fingers hurt abit, I can’t explain the issue but basically; try this code out.

as for client code: you should be firing like this:
Rejoin:FireServer(game.PlaceId, game.JobId)

Its finnaly worked! Thank you!

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