How do i teleport a player to the cframe of a part using the part name?

I’m trying to make a script that teleports a player back and fourth from 2 parts, I understand that I can use the part position but I want to make it so in the script it says the parts name instead of coordinates
this is what i have now
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(0,0,0)
I want it to be something like this
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new("Part1")
I’m not sure how to go about doing this please help

You can use tables for that.

local CFrames = {
	["Part1"] = CFrame.new(0, 0, 0),
	["Part2"] = CFrame.new(2, 2, 2),
}

game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = CFrames["Part1"]
1 Like

this makes sense but its not really a solution because i want to do it without using coordinates just part names

1 Like

You could also do something like this:

game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = workspace.Part1.CFrame
1 Like

i tried it and it didn’t work :face_with_diagonal_mouth:

1 Like

Based on the title, I’d do

HumanoidRootPart.CFrame = workspace:WaitForChild"partName".CFrame

1 Like

They were asking for getting a CFrame from a Part’s name, not a table.

1 Like