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
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
: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)
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.