Teleport to private server and Reserving server doesnt work properly

So im currently making a script where if you click a button it will teleport the clicker to a place and by people i meant only One people which is the player that click the UI. The issue here is that when they are teleported they can join other people games too while i want it so the player is just alone.

Local Script:

GUI.SinglePlayerButton.Activated:Connect(function()
	print("Teleporting")
	TPEvent:FireServer()
end)

Server:

local reservedserver = game:GetService("TeleportService"):ReserveServer(16553994071)
local TS = game:GetService("TeleportService")

event.OnServerEvent:Connect(function(player)
	local playerlist = {}
	table.insert(playerlist, player)
	TS:TeleportToPrivateServer(16553994071,reservedserver,playerlist)
end)
local TS = game:GetService("TeleportService")

event.OnServerEvent:Connect(function(player)
	local playerlist = {}
	table.insert(playerlist, player)	
	TS:TeleportToPrivateServer(16553994071,TS:ReserveServer(16553994071),playerlist)
end)
2 Likes

Thanks it worked, But im still wondering why my old code didnt work tho

You declared the variable beforehand, so it will always go back to that same variable (the reserved server). For it to not do that, we have to put the TS:ReserveServer(16553994071) part in the arguments, so it changes every single time the functions fires.

If that doesn’t make sense then look at this:

local a = math.random(1,100) -- Lets say the number is 50

event.OnServerEvent:Connect(function(player)
	print(a, math.random(1,100) -- 50, (random number, will always change).
end)
1 Like

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