Teleport script only teleports one person

So basically, I’m trying to make a teleport system, but it only teleports one person. What is going on???

-- part1
game.ReplicatedStorage.Te:FireAllClients()
-- part2
game.ReplicatedStorage.OnServerEvent:Connect(function()
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = game.Workspace:WaitForChild("LoadedMap").SpawnPlayersToMap.CFrame
end
end)

EDIT: Ok so I know why this isn’t working… I think I know the solution now, let me solve it…

Yeah saw it later too my fault.

for _, player in pairs(game.Players:GetPlayers()) do
local char = player.Character
char.HumanoidRootPart.CFrame = game.Workspace:WaitForChild("LoadedMap").SpawnPlayersToMap.CFrame
end

Maybe this works?

local playerName = "playerNameHere" -- recommend using userid
for _, player in pairs(game.Players:GetPlayers()) do
if player.Name == playerName then
player.Character.HumanoidRootPart.CFrame = game.Workspace:WaitForChild("LoadedMap").SpawnPlayersToMap.CFrame
end
end

oh

for _, player in pairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = game.Workspace:WaitForChild("LoadedMap").SpawnPlayersToMap.CFrame
end

I dont see why this wouldn’t work:

for _, player in pairs(game.Players:GetPlayers()) do
    player.Character.HumanoidRootPart.CFrame = workspace:WaitForChild("LoadedMap").SpawnPlayersToMap.CFrame
end

Have you tested this with multiple players?

Off topic, but half these posts on this thread made me cringe.

@OP, you should really be checking as well if the Character exists as well.

for i,v in next, game.Players:GetPlayers() do
	if v.Character then
		v.Character.HumanoidRootPart.CFrame = workspace.Part.CFrame
	end
end
1 Like

This code will teleport all players. If you set up a local server with 2 or more players, they will all be teleported. Try it out

Still only one player get teleported

Wouldn’t recommend taking any of these other poster’s code. Using mine works.

Only one player gets teleported

Then you’re not doing it correct…at all. Legit just tested it with an 8 player server and it worked.

  '''
         for i,v in next, game.Players:GetPlayers() do
if v.Character then
	v.Character.HumanoidRootPart.CFrame = workspace:WaitForChild("LoadedMap").SpawnPlayersToMap.CFrame
 end
end
         '''

Why are you using a waitforchild? Just direct hierarchy works perfectly…

Because then it wouldn’t teleport anyone at all

Yes…it will…
Listen, you’re being spoonfed and with working code, don’t try to argue without attempting at all to fix on your own.

Use this tutorial provided by Roblox itself on how to teleport every player within a game to a specific location:

If you’re still having issues then you’re more than likely doing something wrong.
P.S. Before coming to Scripting Support for something, I suggest to first investigate it on https://developer.roblox.com since they have tons of tutorials to teach devs learning the ways of scripting.

1 Like

Ok this works for me so I thinks this works for you too.

for i,v in pairs(game.Players:GetChildren()) do
	v.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Part.Position)
end

By myself I added a wait function so I can test it because it takes time to load the characters in.

Wait I think I know why… So basically, this teleport thing is in a round script, and I put all of the ends at the bottom so that the code runs, and them repeats again. (I put a while true do loop at the top so it loops)

while true do
for i,v in pairs(game.Players:GetChildren()) do
	v.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Part.Position)
   end
end