Auto Re-Join system gives me and error

Ello!

So I have an afk room and I am trying to make it so that right before the player has been afk for 20 minutes it reconnects the player to server and resets it. (This is done in many popular games like Pet sim and bedwars)

and right now it works great! the problem is that when I rejoin it gives me error and wont let me play, I have to either reconnect or leave.

Image of error:
Screenshot 2025-01-17 at 7.50.33 AM

Server:

local RejoinRemote = Instance.new("RemoteEvent")
RejoinRemote.Name = "RejoinRemote"
RejoinRemote.Parent = game.ReplicatedStorage

RejoinRemote.OnServerEvent:Connect(function(Player)
	local teleportData = {
		autoRejoin = true
	}

	local teleportOptions = Instance.new("TeleportOptions")
	teleportOptions:SetTeleportData(teleportData)

	local attemptIndex = 0
	local success, result 
	repeat
		success, result = pcall(function()
			return game:GetService("TeleportService"):Teleport(game.PlaceId, Player, teleportOptions)
		end)
		attemptIndex += 1
		if not success then
			warn("Teleport failed: " .. tostring(result))
			task.wait(2)
		end
	until success or attemptIndex == 4
end)

game.Players.PlayerAdded:Connect(function(Player)
	local JoinData = Player:GetJoinData()
	if JoinData.autoRejoin then
		--I will use this later
	
	end
end)




Client:

local ReqMins = 15-- would usually be this 17 * 60
local RejoinRemote = game.ReplicatedStorage:WaitForChild("RejoinRemote")
local userInputService = game:GetService("UserInputService")
local Time = 0

userInputService.InputBegan:Connect(function()
	Time = 0
end)

userInputService.InputEnded:Connect(function()
	Time = 0
end)

while task.wait(1) do
	Time += 1
	if Time >= ReqMins then
		RejoinRemote:FireServer()
		break
	end
end

1 Like

All this happens because you sort of teleport a player to a non-existent server (that is, you play alone on the created server and after teleporting the player, the player has nowhere to teleport because the server is closed because you left), for example, if your project played at least one more person, most likely everything would work without errors, I hope I explained it clearly :slight_smile: I already had such a problem.

Do you know of any way to fix this?

try teleporting a player to a private server or you just need to have more than 2 players in your game, or I don’t know bro.

You need to reserve a server as the server you teleport to will be shut down before you can get there as theres nobody in it

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