How to make 2 players teleport at the same time

I am trying to make a hop on features, where two players hop on spots, and when both players are on the spot, it teleports them both to one place. I have looked into making a table for the two players, but that doesn’t seem to work for me.

This is my current part of the script where I have an issue, Currently whenever one player hops on it waits 5 seconds, and it teleports them, but for the other player, I must hop off then back on for the player to then teleport after 5 seconds.

	
	while hSpotOccupied.Value == true and aSpotOccupied.Value == true do
		if aSpotOccupied.Value == true and hSpotOccupied.Value == true then
			wait(5)
			aPlr.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(AwayTPOn.Position)
			hPlr.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(HomeIntroTP.Position)
			wait(.5)
			break
		else
			break
		end
	end
	end)
end)```

Are you teleporting a player 5 seconds after they hop on? Maybe you might need to insert the players into a table and only start teleporting if that table full of 2 players is actually full of 2 players

I attempted to make a table of both of the players who hop on, hPlr and aPlr, but that didn’t seem to work out for me as they would both teleport to the same position, I am trying to get both players to teleport to separate parts. AwayIntroTP and HomeIntroTP

Then why don’t you assign either of them to an array and have the script that’s teleporting them put them in where they need to be according to what index they are in the array, like

local playertargets = {
      ["hPlr"] = --player 1,
      ["aPlr"] = --player 2
   }

-- code to teleport both players to designated places

How would I assign both players where to go after the table? That’s more where I am struck than creating the table.

Use the array example i used and teleport based on the index

local playertargets = {
      ["hPlr"] = --player 1,
      ["aPlr"] = --player 2
   }

playertargets.hPlr:PivotTo(CFrame.new()) -- where hPlr should be teleported to
playertargets.aPlr:PivotTo(CFrame.new()) -- where aPlr should be teleported to

Just tested, still having the same issue where only one player teleports at a time. I am going to double check the code.

Double checked the code, it’s not teleporting as intended, and I see no mistakes, but, this code right here works, but it is only teleporting one player at a time, whenever both players are on the spot, it teleports one, and the other would have to hop off and back on to be teleported.

	
	while hSpotOccupied.Value == true and aSpotOccupied.Value == true do
		if aSpotOccupied.Value == true and hSpotOccupied.Value == true then
			wait(5)
			aPlr.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(AwayTPOn.Position)
			hPlr.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(HomeIntroTP.Position)
			wait(.5)
			break
		else
			break
		end
		end
	end)```

This won’t fix your issue but instead of = CFrame.new(AwayTPOn.Position) just do = AwayTPOn.CFrame.

Ill start using that more often when using CFrame, thanks!

function tpPlayer1(player1)
      player1.Character:WaitForChild("HumanoidRootPart").CFrame = AwayTPOn.CFrame
end

function tpPlayer2(player2)
      player2.Character:WaitForChild("HumanoidRootPart").CFrame = HomeIntroTP.CFrame
end

	while hSpotOccupied.Value == true and aSpotOccupied.Value == true do
		if aSpotOccupied.Value == true and hSpotOccupied.Value == true then
			wait(5)
			tpPlayer1(aPlr)
            tpPlayer2(hPlr)
			wait(.5)
			break
		else
			break
		end
	end
	end)
end)