Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to teleport to a private server giving error argument 3 missing or nil? (Answered)

So, I know that in studio you cant teleport and it gives an error. So I went in game, and tested it. It gave the error argument 3 missing or nil, on line 24. How do I get the players, if they have the bool value, to teleport to the place? I dont want everyone to teleport there, just the players with the bool value. How would I do that? If I could get the players names, I would just teleport them. But they would have to be in a variable. Half the code, is just for difficulty, the bottom is the teleporting part.

local remote = game.ReplicatedStorage.StartEvent
remote.OnServerEvent:Connect(function()
	for i, v in pairs(game.Players:GetPlayers()) do
		local bool = v:FindFirstChildOfClass("BoolValue")
			local frame = v.PlayerGui.ActiveLobbys.Frame.Frame.Frame
			local player2 = frame.PlayerName.Text
			local gameplaceid = 3313994275
				if bool then
					print("Start")
					if bool.Name == player2 then
					if frame.Difficulty.Text == "Medium" then
						gameplaceid = 3313994275
						
						elseif frame.Difficulty.Text == "Hard" then
							gameplaceid = 3313994275
						end
				
		end
			local TeleportService = game:GetService("TeleportService")
			local Reserve = TeleportService:ReserveServer(gameplaceid)
	 
			--local Players = game.Players:GetPlayers() --// Returns an array of all Players
	 
			TeleportService:TeleportToPrivateServer(gameplaceid, Reserve)--, Players)
			--end
		end  
    end
end)

1 answer

Ok, I think this is working. I found a developer post here's the link: https://devforum.roblox.com/t/adding-players-to-a-table/270008 . I used the code there, and now my teleporting works! I knew that the problem, was I didn't have 3 values in the teleporting code at the end (yes, thats how it works.) But I didn't know how to get the players that I wanted to teleport. But now, thanks to that code, it works! I'm not sure if it's teleporting me to the right place yet, though. This is now my code:

local remote = game.ReplicatedStorage.StartEvent
remote.OnServerEvent:Connect(function(player)
	for i, v in pairs(game.Players:GetPlayers()) do
		local bool = v:FindFirstChildOfClass("BoolValue")
		local frame = v.PlayerGui.ActiveLobbys.Frame.Frame.Frame
		local player2 = frame.PlayerName.Text
		local gameplaceid = 3313994275
		local Player = player
		local PlayersToTeleport = {}
		local AlreadyInTable = false

			for _,OtherPlayer in next,PlayersToTeleport do
				if OtherPlayer == Player then
				AlreadyInTable = true
			end
		end
		if not AlreadyInTable then
		-- Add them to the array!
			table.insert(PlayersToTeleport,Player)
		end
				if bool then
					print("Start")
					if bool.Name == player2 then
					if frame.Difficulty.Text == "Medium" then
						gameplaceid = 3313994275
						
						elseif frame.Difficulty.Text == "Hard" then
							gameplaceid = 3313994275
						end
				
		end
			local TeleportService = game:GetService("TeleportService")
			local Reserve = TeleportService:ReserveServer(gameplaceid)
	 
			TeleportService:TeleportToPrivateServer(gameplaceid, Reserve, PlayersToTeleport)--, Players)
			--end
		end  
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.