How can I teleport players to a private server with teleport data from the server?

Is there a way to fully teleport a player(s) to a private server with teleport data? I don’t want to do this locally because I am afraid exploiters can change the data to their advantage. Here is my code (from the server):

        local ServerCode = game:GetService("TeleportService"):ReserveServer(0000) -- changed from actual game
		local players = {}
		
		local children = game.Players:GetChildren()
		
		local worked, errorData = pcall(function()
			print(1)
			for i = 1, #children do
				local plr = children[i]
				table.insert(players , plr)
			end
			wait(1)
			
			local TeleportData = {
				money = 100;
                bubbles = 100;
			}
			
			game:GetService("TeleportService"):TeleportToPrivateServer(5672930192, ServerCode, players, TeleportData)

Any help would be appreciated, thank you!

1 Like

As per the api-reference states, the 4th argument should be the spawnName which the players should teleport to. Thankfully, this is optional and the 5th argument shall be the teleportData.

Furthermore, you can just add a nil argument:

game:GetService("TeleportService"):TeleportToPrivateServer(5672930192, ServerCode, plrs, nil, TeleportData)

P.S: I recommend defining TeleportService as a variable, this will prevent you from using GetService reptitively.

2 Likes

Thanks! This helped a lot, much appreciated!

1 Like