Prevent players from joining reserved server

Dear Developers,
I NEED YOUR HELP!
i made a teleport system similar to most of the Story games, but i have a huge problem:
the teleport will (after the players got teleported) still teleport every future player to the same server.
I need help as soon as possible!
Huge thanks to everyone who tries to help me!

You need to provide code. What are the properties of the TeleportOptions?

Since you did not provide a code, I created one for you. Give it a try and let me know how it goes.

-- Replace SERVER_ID with the ID of your reserved server
local SERVER_ID = 123456789

game.Players.PlayerAdded:Connect(function(player)
    -- Check if the player is trying to join the reserved server
    if game.JobId == "rbxassetid://" .. SERVER_ID then
        -- Kick the player and display a message
        player:Kick("This server is reserved and cannot be joined.")
    end
end)

This script listens for players joining the game and checks if the game. JobId matches the reserved server ID. If it does, the script kicks the player and displays a message indicating that the server is reserved and cannot be joined. You’ll need to replace SERVER_ID with the actual ID of your reserved server.

This code is useless since reserved servers are private and can’t be joined by other players if not teleported by the game with the access code by default.

The problem here seems to be that the game is teleporting every player to a reserved server so @WHOTEI should provide us the script being used.

THE CODE LOOKS LIKE THIS:

local TweenService = game:GetService("TweenService")
local placeId = script.Place_ID.Value
local teleporting = false
local spawnTeleport = script.ENTER_Pos.Value
local Leave_TP = script.LEAVE_PART.Value

script.Gui.Value.Frame.players.Text = "Players: " ..#script.People:GetChildren().. "/"..script.Player_Limit.Value..""

local function updateGui()
	script.Gui.Value.Frame.players.Text = "Players: " ..#script.People:GetChildren().. "/"..script.Player_Limit.Value..""
end

local function removeFromList(Character)
	script.People:FindFirstChild(""..game.Players:GetPlayerFromCharacter(Character).Name..""):Destroy()
	updateGui()
end

function Teleport_Players()
	script.Gui.Value.Frame.Status.Text = "TELEPORTING..."
	local ServerCode = game["Teleport Service"]:ReserveServer(placeId)
	for a, b in ipairs(script.People:GetChildren()) do

		local Player = b.Value
		if Player then
			game["Teleport Service"]:TeleportToPrivateServer(placeId,ServerCode,{Player})

			task.wait()
		else
		end
	end
	for a, b in ipairs(script.People:GetChildren()) do
		b:Destroy()
	end
	script.Gui.Value.Frame.Status.Text = "READY"
	ServerCode = nil
	print("Reseted ID")
end


script.ENTER_PART.Value.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then

		local char = hit.Parent
		local player = game.Players:FindFirstChild(char.Name)
		local alreadyExists = false

		if not script.People:FindFirstChild(""..player.Name.."") then
			if #script.People:GetChildren() < script.Player_Limit.Value then
				local Val = Instance.new("ObjectValue",script.People)
				Val.Name = player.Name
				Val.Value = player
				char.PrimaryPart.CFrame = spawnTeleport.CFrame
				updateGui()
				task.wait(1)
				if #script.People:GetChildren() == script.Player_Limit.Value then
					Teleport_Players()
				end

				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end
		end
	end
end)



script.Prompt.Value.Triggered:Connect(function(player)
	if player.Character then
		local RootPart = player.Character.HumanoidRootPart
		RootPart.Anchored = true
		player.Character.Humanoid.Jump = true
		task.wait()
		game.TweenService:Create(RootPart,TweenInfo.new(0,Enum.EasingStyle.Linear),{CFrame = script.LEAVE_PART.Value.CFrame}):Play()
		task.wait(0.2)
		removeFromList(player.Character)
		RootPart.Anchored = false
	end
end)

my main problem is that it wont reserve a different server after every group has been teleported.

local TweenService = game:GetService("TweenService")
local placeId = script.Place_ID.Value
local teleporting = false
local spawnTeleport = script.ENTER_Pos.Value
local Leave_TP = script.LEAVE_PART.Value

script.Gui.Value.Frame.players.Text = "Players: " ..#script.People:GetChildren().. "/"..script.Player_Limit.Value..""

local function updateGui()
	script.Gui.Value.Frame.players.Text = "Players: " ..#script.People:GetChildren().. "/"..script.Player_Limit.Value..""
end

local function removeFromList(Character)
	script.People:FindFirstChild(""..game.Players:GetPlayerFromCharacter(Character).Name..""):Destroy()
	updateGui()
end

function Teleport_Players()
	script.Gui.Value.Frame.Status.Text = "TELEPORTING..."
	local ServerCode = game["Teleport Service"]:ReserveServer(placeId)
	for a, b in ipairs(script.People:GetChildren()) do

		local Player = b.Value
		if Player then
			game["Teleport Service"]:TeleportToPrivateServer(placeId,ServerCode,{Player})

			task.wait()
		else
		end
	end
	for a, b in ipairs(script.People:GetChildren()) do
		b:Destroy()
	end
	script.Gui.Value.Frame.Status.Text = "READY"
	ServerCode = nil
	print("Reseted ID")
end


script.ENTER_PART.Value.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then

		local char = hit.Parent
		local player = game.Players:FindFirstChild(char.Name)
		local alreadyExists = false

		if not script.People:FindFirstChild(""..player.Name.."") then
			if #script.People:GetChildren() < script.Player_Limit.Value then
				local Val = Instance.new("ObjectValue",script.People)
				Val.Name = player.Name
				Val.Value = player
				char.PrimaryPart.CFrame = spawnTeleport.CFrame
				updateGui()
				task.wait(1)
				if #script.People:GetChildren() == script.Player_Limit.Value then
					Teleport_Players()
				end

				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end
		end
	end
end)



script.Prompt.Value.Triggered:Connect(function(player)
	if player.Character then
		local RootPart = player.Character.HumanoidRootPart
		RootPart.Anchored = true
		player.Character.Humanoid.Jump = true
		task.wait()
		game.TweenService:Create(RootPart,TweenInfo.new(0,Enum.EasingStyle.Linear),{CFrame = script.LEAVE_PART.Value.CFrame}):Play()
		task.wait(0.2)
		removeFromList(player.Character)
		RootPart.Anchored = false
	end
end)

function Teleport_Players()
    script.Gui.Value.Frame.Status.Text = "TELEPORTING..."
    local ServerCode = tostring(math.random(1000000,9999999)) -- generate a unique code
    for a, b in ipairs(script.People:GetChildren()) do
        local Player = b.Value
        if Player then
            game["Teleport Service"]:TeleportToPrivateServer(placeId,ServerCode,{Player})
            task.wait()
        end
    end
    for a, b in ipairs(script.People:GetChildren()) do
        b:Destroy()
    end
    script.Gui.Value.Frame.Status.Text = "READY"
    ServerCode = nil
    print("Reseted ID")
end

You should try using TeleportAsync() for teleporting the players

function Teleport_Players()
	script.Gui.Value.Frame.Status.Text = "TELEPORTING..."
	local TeleportOptions = Instance.new("TeleportOptions")
    TeleportOptions.ShouldReserveServer = true
local Players = {}
for a, b in ipairs(script.People:GetChildren()) do
        local Player = b.Value
        if Player then
      table.insert(Players,Player)
     end
    end
	game["Teleport Service"]:TeleportAsync(placeId,Players,TeleportOptions)
for a, b in ipairs(script.People:GetChildren()) do
        b:Destroy()
    end
	script.Gui.Value.Frame.Status.Text = "READY"
end

I haven’t tested the code so it might not work but this is what I would use for teleporting players to a private server.

1 Like

it this better than shouldreserveserver???

THIS RETURNS ERROR “attempting to call a boolvalue”

this returns error: attempting to teleport to a restricted place ):

Sorry I seem to have done the teleport options wrong, try replacing

TeleportOptions.ShouldReserveServer(true)

with

TeleportOptions.ShouldReserveServer = true

wont work too… is there any other solution for that???

the players are still inside the same server… everyone using the teleport box , no matter when, is at the samee server! pls help!

I wouldn’t know why it doesn’t work, maybe try this?

function Teleport_Players()
	script.Gui.Value.Frame.Status.Text = "TELEPORTING..."
	local TeleportOptions = Instance.new("TeleportOptions")
    TeleportOptions.ShouldReserveServer = true
    local Players = {}
    for a, b in ipairs(script.People:GetChildren()) do
         table.insert(Players,game.Players[b.Name])
    end

	game["Teleport Service"]:TeleportAsync(placeId,Players,TeleportOptions)

    for a, b in ipairs(script.People:GetChildren()) do
        b:Destroy()
    end
	script.Gui.Value.Frame.Status.Text = "READY"
end

This is similar to how I did it in one of my games and from what I am aware of this should work(though like before I haven’t tested whether it works or not)

1 Like

still wont work. maybe its because of that it is a table?