So I am working on a game which requires teleportation scripts. I know how to teleport parts, but not players. I am not really looking for a command just a bit of code used to teleport all the players in the server.
Any help appreciated!
So I am working on a game which requires teleportation scripts. I know how to teleport parts, but not players. I am not really looking for a command just a bit of code used to teleport all the players in the server.
Any help appreciated!
character:SetPrimaryPartCFrame(new cframe)
Player.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new()
You will have to move the humanoidrootpart.
Place this script in ServerscriptService.
local Part = game.Workspace.Part – Change to the part path
local Part2 = game.Workspace.Part2 – Change to the part path the player get teleported toPart.Touched:Connect(function(hit) – The standart touch event
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.HumanoidRootPart.Position = Part2.Position + Vector3.new(0, 1, 0)
end
end)
Make sure Part2’s CanCollide is set to false. Also make sure both Parts are anchored. You can remove the + Vector3.new(0, 1, 0)
if you don’t want the player to spawn 1 stud above the part.
To teleport all players at once:
local players = game:GetService("Players")
local playerList = players:GetChildren()
for i, player in pairs(playerList) do
local character = player.Character
local HMR = character:WaitForChild("HumanoidRootPart")
HMR.CFrame = CFrame.new(x, y, z)
end
Changing the position won’t work properly
local h = script.Parent:WaitForChild("Humanoid")
local dir = --direction
h:MoveTo(dir)
local ps = game:GetService("Players")
for i,v in pairs(ps:GetPlayers()) do
if v.Character then
local root = v.Character:FindFirstChild("HumanoidRootPart")
if root then
root.CFrame = CFrame.new(TeleportPosition,root.CFrame.LookVector)
end
end
character:moveto(part) is what I’d pick since it’s so simple
To teleport all player’s in the server:
local Players = game:GetService("Players")
for i, v in pairs(Players:GetChildren()) do
local Character = v.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
HumanoidRootPart.CFrame = CFrame.new(x, y, z)
end
This looks identical to what I posted.
Oof. Unfortunately, this script does not work. Thanks for the help tho!
local players = game:GetService("Players")
local playerList = players:GetChildren()
for i, player in pairs(playerList) do
local character = player.Character
local HMR = character:WaitForChild("HumanoidRootPart")
HMR.CFrame = CFrame.new(x, y, z)
end
It wouldn’t work like this, you need to change the values of “x”, “y” and “z” to actual number values representing the position you want to teleport the players to. I’m not going to fill those in myself because I don’t know where you want to teleport the players to.
I’d recommend PivotTo instead.
As it says here:
Transforms the PVInstance
along with all of its descendant PVInstances
such that the pivot is now located at the specified CFrame
. This is the primary function that should be used to move Models
via scripting.
This function has been superseded by PVInstance:PivotTo
which acts as a more performant replacement and does not change your code’s behavior. Use PVInstance:PivotTo
for new work and migrate your existing Model:SetPrimaryPartCFrame
calls when convenient.
Yep ik I did fill it out but in the output it said something about the indexes in your for loop I think?
local players = game:GetService("Players")
task.wait(5)
local playerList = players:GetPlayers()
for i, player in pairs(playerList) do
local character = player.Character or player.CharacterAdded:wait()
character:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))
end
Test with this, it works my end. It’s a server script so place it inside the workspace, wait 5 seconds and it’ll teleport you back to the center of the baseplate/map. I’ve set the CFrame values for you.