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.ServerInstanceId = game.JobId
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
task.wait(2)
end
until success or attemptIndex == 4
end)
game.Players.OnPlayerAdded:Connect(function(Player)
local JoinData = Player:GetJoinData()
if JoinData.autoRejoin then
-- Teleport to afk room
end
end)
Local
local ReqMins = 17
local RejoinRemote = game.ReplicatedStorage:WaitForChild("RejoinRemote");
local Time = 0
game.Players.LocalPlayer:GetMouse().Move:Connect(function() Time = 0 end)
game:GetService("UserInputService").InputEnded:Connect(function() Time = 0 end)
ReqMins *= 60
while task.wait(1) do
Time += 1;
if Time >= ReqMins then
RejoinRemote:FireServer()
break
end
end