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:
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