Convert this from Position to CFrame

I am trying to make a zipline and tween the character’s position to the zipline’s end, and I’m using HRP.Position. I’ve heard that you should you CFrame instead of Position, and I wanna do that. Let me show you the differences:

(Position)

(CFrame)

Script
StartPrompt.Triggered:Connect(function(Player)
	if CharacterValue.Value then return end
	StartPrompt.Enabled = false
	EndPrompt.Enabled = false
	local Character = Player.Character
	CharacterValue.Value = Character
	local Humanoid = Character.Humanoid
	local Animator = Humanoid.Animator
	local HRP = Character.HumanoidRootPart

	local ZipAnim

	local Distance = (Character.HumanoidRootPart.Position - EndZip.NeonCore.Position).Magnitude
	local Time = Distance / 25
	local Diff = 5
	
	HRP.CFrame = CFrame.new(StartPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0))
	HRP.CFrame = CFrame.lookAt(HRP.Position,EndPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0))

	local Tween = TweenService:Create(
		HRP,
		TweenInfo.new(
			Time,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		),
		{
			--Position = EndPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0)
			CFrame = CFrame.new(EndPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0)),
		}
	)

	HRP.Anchored = true
	
	if Humanoid.RigType == Enum.HumanoidRigType.R15 then
		ZipAnim = Animator:LoadAnimation(ReplicatedStorage.Animations.ZipLine.AnimR15)
	elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
		ZipAnim = Animator:LoadAnimation(ReplicatedStorage.Animations.ZipLine.AnimR6)
	end

	Tween:Play()
	ZipAnim:Play()

	Tween.Completed:Wait()

	ZipAnim:Stop()
	HRP.Anchored = false
	CharacterValue.Value = nil
	StartPrompt.Enabled = true
	EndPrompt.Enabled = true
end)

How should I fix this?

2 Likes

i have an idea: put in the position value into the cframe instead of trying to convert it

that way your sort of indirectly converting it

just use CFrame.Position to change a CFrame’s position value

1 Like

Is there CFrame.Position? How exactly should I change it?

1 Like

i trust that you know how to do it already since CFrame.Position can be changed if you just put in a vector3

1 Like

The thing is, how would I do that, and where? Because if I put it in the tween table, it just gives me an error.

{
	CFrame.Position = EndPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0)
}

Expected ‘}’ (to close ‘{’ at line 51), got ‘=’

1 Like

local cframe = CFrame.new()
local newPosition = vector3.new(0,3,0)
cframe.Position = newPosition

print(cframe.Position)

1 Like

Getting the error

Position cannot be assigned to

1 Like

maybe try creating a cframe with Only the position data

1 Like

local CFrame = CFrame.new(Position)

1 Like

Already doing that, remember? I just need to nullify the rotation.

1 Like

try this

CFrame.new(Position, Position to look at)

cframe has two arguments

just put vector3 for both of them

1 Like

This constructor overload has been replaced by CFrame.lookAt , which accomplishes a similar goal. It remains for the sake of backward compatibility.


The thing is that it gives me an error too.

1 Like

local vector3one = Vector3.new(0,0,0)

local vecot3two = Vector3.new(0,1,0)

local cframe = CFrame.new(vector3one, vecot3two)

print(cframe)

this works fine with no errors

i dont see why you need to use cframe.lootAt

1 Like

It is a more not buggy method, as the DevHub states.

1 Like

And I’ve tried your solution, and the character doesn’t rotate, but it doesn’t move as well.

1 Like
while wait() do
	local vector3one = script.Parent.Position
	local vecot3two = workspace["L85A2 Stock"].Body.Position
	local cframe = CFrame.new(vector3one, vecot3two)
	script.Parent.CFrame = cframe
end

above is the script, below is the visual that came from the results of the script

1 Like

explain what the buggy part to me is

i have never seen a bug from using CFrame.new

1 Like

It’s not a rotation issue, as I mentioned, the character isn’t moving.

The buggy method is a method that DevHub doesn’t want the developers use, but it wasn’t removed to not break games.

1 Like

Hey!

Try This

StartPrompt.Triggered:Connect(function(Player)
	if CharacterValue.Value then return end
	StartPrompt.Enabled = false
	EndPrompt.Enabled = false
	local Character = Player.Character
	CharacterValue.Value = Character
	local Humanoid = Character.Humanoid
	local Animator = Humanoid.Animator
	local HRP = Character.HumanoidRootPart

	local ZipAnim

	local Distance = (Character.HumanoidRootPart.Position - EndZip.NeonCore.Position).Magnitude
	local Time = Distance / 25
	local Diff = 5
	
	local StartCFrame = StartPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0)
	local EndCFrame = EndPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0)
	
	HRP.CFrame = CFrame.new(StartCFrame,EndCFrame)
	
	local Tween = TweenService:Create(
		HRP,
		TweenInfo.new(
			Time,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		),
		{
			--Position = EndPrompt.Parent.WorldPosition + Vector3.new(0,Diff,0)
			CFrame = CFrame.new(EndCFrame,EndCFrame)
		}
	)

	HRP.Anchored = true

	if Humanoid.RigType == Enum.HumanoidRigType.R15 then
		ZipAnim = Animator:LoadAnimation(ReplicatedStorage.Animations.ZipLine.AnimR15)
	elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
		ZipAnim = Animator:LoadAnimation(ReplicatedStorage.Animations.ZipLine.AnimR6)
	end

	Tween:Play()
	ZipAnim:Play()

	Tween.Completed:Wait()

	ZipAnim:Stop()
	HRP.Anchored = false
	CharacterValue.Value = nil
	StartPrompt.Enabled = true
	EndPrompt.Enabled = true
end)
1 Like

then idk what you want

cuz two videos above looks like their doing fine

1 Like