function teleportPlayers(position)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
player.Character:PivotTo(CFrame.new(position))
end
end
teleportPlayers(-60, 21.214, -28.5)
This is a code snippet. When it gets to the line that calls the function, this error appears:
Because your sending it multiple number instead of a vector3.
When calling the function just send it a CFrame value with CFrame.New
Then when using the PivotTo function give it the position parameter
function teleportPlayers(position)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
player.Character:PivotTo(position)
end
end
teleportPlayers(CFrame.New(-60, 21.2, -28.5))
^ this reply is correct, But you should add a Vector3.new() inside the CFrame.new() since CFrame.new() doesnt accept individual values: turns out it acutally does accept individual values but id still recommend using Vector3.new()
function teleportPlayers(position)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
player.Character:PivotTo(position)
end
end
teleportPlayers(CFrame.New(Vector3.new(-60, 21.2, -28.5)))
You could also add a failsafe incase the player doesnt currently have a character:
function teleportPlayers(position)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if not player.Character then continue end
if not player.Character:FindFirstChild("HumanoidRootPart") then continue end
player.Character:PivotTo(position)
end
end
teleportPlayers(CFrame.New(Vector3.new(-60, 21.2, -28.5)))
Thanks! This works, but I wanted to make it cleaner and easier to write so I did this:
function teleportPlayers(position)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if not player.Character then continue end
if not player.Character:FindFirstChild("HumanoidRootPart") then continue end
player.Character:PivotTo(CFrame.new(position))
end
end
That also worked
But then i thought, if i could do that, why not this:
function teleportPlayers(position)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if not player.Character then continue end
if not player.Character:FindFirstChild("HumanoidRootPart") then continue end
player.Character:PivotTo(CFrame.new(Vector3.new(position)))
end
end
This did not work. It teleported me, but it teleported me way into the ground for some reason., even if I change the Y value a lot it still teleports me into the ground. Shouldn’t it be the same? Please explain what’s going on here
In the second example you are creating a new vector 3 with 1 variable. The Vector3.new() constructor wants 3 variables, not just a single one. If you want to do it this way you would need to change the input argument to your function to be X, Y, Z and then instead of position in Vector3.New() youd put the X, Y and Z variables
function teleportPlayers(x, y, z)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if not player.Character then continue end
if not player.Character:FindFirstChild("HumanoidRootPart") then continue end
player.Character:PivotTo(CFrame.new(Vector3.new(x, y, z)))
end
end
teleportPlayers(427, 73, 682) --Example position
In order to keep their orientation im pretty sure you can do this, but i havent tested it yet as im not home currently:
function teleportPlayers(x, y, z)
local Pos = Vector3.new(x, y, z)
for _,player in pairs(game:GetService("Players"):GetPlayers()) do
if not player.Character then continue end
if not player.Character:FindFirstChild("HumanoidRootPart") then continue end
local RootPartCFrame = player.Character.HumanoidRootPart.CFrame
player.Character:PivotTo(CFrame.LookAt(Pos, Pos + RootPartCFrame.LookVector))
end
end
teleportPlayers(427, 73, 682) --Example position