How to teleport all players in a server?

I’m trying to make a game like a round game, but I need to teleport all the players to a sertend place, but I can’t seem to do it or find a solution, so can someone please help me!

this was what I tried.

for i,v in pairs(game.Workspace:GetChildren()) do
	if v:FindFirstChild("Humanoid") then
		v.Position = ---- part
	end
end
1 Like

do this

for _, Player in pairs(Players:GetPlayers()) -- make sure u have a Variable called Players for Players Service
	local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait()
	Character:PivotTo(CFrame) -- Change "CFrame" to the Part/Target CFrame inside the ()
end
For _,player in pairs(Game.Players:GetChildren()) do
   Local char = player.Character
   If char then
      Local hrp = char:FindFirstChild(“HumanoidRootPart”)
      If hrp then
         Hrp.CFrame = part.CFrame
      end
   end
end
for i, plr in pairs(game.Players:GetChildren()) do 
      local c = plr.Character
      if c then
            c:MoveTo(Vector3.new(X, Y, Z))
      end
end

Why MoveTo() he wants to teleport the players, also you can only use that on a Humanoid.

:MoveTo() is actually valid on models or parts just like :PivotTo(). However, I do agree that :PivotTo() should be used in this context because the former takes collision into account and may not accurately teleport to a certain position (i.e. spawning on the roof)

3 Likes

This code seems AI generated, tons of errors.

Starting with,
Game is deprecated. Use game instead

Instead of using Players:GetChildren() run Players:GetPlayers()

Local will result in an error, local is the correct syntax.
Same applies to If, use if

Hrp is not defined, hrp is as variables are case-sensitive.

Your code can be shrunk and corrected into

local part = define_part_here

for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
	-- Does not continue script if not Player.Character 
	if not player.Character then continue end 

	-- Player.Character.PrimaryPart is set to the HumanoidRootPart by default
	player.Character.PrimaryPart:PivotTo(part.CFrame)
end

-- Edit: Fixed logic, just so my profile history looks good.

This however, only runs if all Players character’s exist. If you want all Characters, dead or alive to eventually teleport to the Part.CFrame, use @PanseRBes’s method. I am just trying to let you know that your method will result in a bucket o’ errors.

1 Like

I know I’m sorry for the inconsistent capitals, and I also forgot about the dead players

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.