Hello, I’m making a RNG Game but a player wanted the rejoin server/bypass the 20 minute kick in Roblox. I couldn’t manage to do it, but this is my best shot. Thank you for helping me make it work! This is part of my code btw, in a serverscript and game player playeradded function.
--// Services
local plrs = game:GetService("Players")
local uis = game:GetService("UserInputService")
local ts = game:GetService("TeleportService")
--// LocalPlayer
local lp = plrs.LocalPlayer
while not lp do
plrs:GetPropertyChangedSignal("LocalPlayer"):Wait()
lp = lp.LocalPlayer
end
--// Vars
local t = 0
--// Reset AFK Counter
uis.InputEnded:Connect(function()t=0 end)
--// AFK Checker
while task.wait(1) do
t+=1
if t >= 900 then
if #plrs:GetPlayers()<=1 then
lp:Kick("Creating new server, do not click Leave...")
task.wait(1)
local s=nil
repeat
s=pcall(function()
return ts:Teleport(game.PlaceId,lp)
end)
if not s then task.wait()end
until s
else
lp:Kick("Rejoining, do not click Leave...")
local s=nil
repeat
s=pcall(function()
return ts:TeleportToPlaceInstance(game.PlaceId,game.JobId,lp)
end)
if not s then task.wait()end
until s
end
break
end
end
If the server has 1 player, it is required for the player to be kicked otherwise the player would be joining a server which is shuting down thereforce causing an error.
You can try this with a kick removed
--// Services
local plrs = game:GetService("Players")
local uis = game:GetService("UserInputService")
local ts = game:GetService("TeleportService")
--// LocalPlayer
local lp = plrs.LocalPlayer
while not lp do
plrs:GetPropertyChangedSignal("LocalPlayer"):Wait()
lp = lp.LocalPlayer
end
--// Vars
local t = 0
--// Reset AFK Counter
uis.InputEnded:Connect(function()t=0 end)
--// AFK Checker
while task.wait(1) do
t+=1
if t >= 900 then
if #plrs:GetPlayers()<=1 then
lp:Kick("Creating new server, do not click Leave...")
task.wait(1)
local s=nil
repeat
s=pcall(function()
return ts:Teleport(game.PlaceId,lp)
end)
if not s then task.wait()end
until s
else
local s=nil
repeat
s=pcall(function()
return ts:TeleportToPlaceInstance(game.PlaceId,game.JobId,lp)
end)
if not s then task.wait()end
until s
end
break
end
end