Script not teleporting all the players?

The script teleports maybe one or two players, but doesn’t the rest of them. Am I doing something wrong?

repeat wait();
    game.Players:FindFirstChild(player).Character.HumanoidRootPart.CFrame = teleports[1].CFrame;
until game.Players:FindFirstChild(player).Character.HumanoidRootPart.CFrame == teleports[1].CFrame;

Funny thing is, it works great when I test it on Roblox Studio (with 5 sessions), but testing it on a live server doesn’t. :confused:

Would this work for you?

function TeleportPlayers()
	for Index, Plr in pairs(players:GetChildren()) do
		if Plr.Character or Plr.CharacterAdded:Wait(2) then
			Plr.Character.HumanoidRootPart.CFrame = teleports[1].CFrame
		end
	end
end

Just fire this function and it should teleport the players

The “Wait()” instance method of events does not receive any parameters, so in this case passing a number value of “2” to it is redundant.

local Players = game:GetService("Players")

for _, Player in ipairs(Players:GetPlayers()) do
	local Character = Player.Character or Player:GetPropertyChangedSignal("Character"):Wait()
	Character:PivotTo(teleports[1].CFrame)
	end
end

Doesn’t that set a limit of how long it can :Wait() for? that’s what I use it for

It’s a parameter-less method, it just yields the thread until the event of which it is called on has fired.

You’re thinking of :WaitForChild(childName, maxTime).

Eh, I’ve used this for pathfinding. But I assume you guys are right, Unless :Wait() and :wait() are different

They are different, the former is an instance method of events and the latter should just be “wait()”, it isn’t an instance method, it’s a global.

for _, Player in ipairs(game.Players:GetPlayers()) do
    local Char = Player.Character or Player.CharacterAdded:Wait()
    Char.HumanoidRootPart.CFrame = teleports[1].CFrame
    print(Player.Name)
end