Player movement offsets Part's position

Hello devs! So I’ve been working on my script, and discovered this issue, as you can see


The hand at the right is above mouse (it’s supposed to be like that)
But as soon as I move

Hand at the right is much further than the mouse’s position.
Code :

local owner = game:GetService("Players").LocalPlayer

local char = owner.Character or owner.CharacterAdded:Wait()

local hum = char:FindFirstChildWhichIsA("Humanoid")

if hum.RigType == Enum.RigType.R15 then

error("This script only supports R6, change your rig type to R6 and run this script again.")

else

print("Script loaded succesfully, enjoy!")

end

local mouse = owner:GetMouse()

local hrp = char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") or char:WaitForChild("HumanoidRootPart")

local currentTarget = nil

local Hand = Instance.new("Part")

local SpecialMesh1 = Instance.new("SpecialMesh")

Hand.Name = "Hand"

Hand.Parent = char

Hand.BrickColor = char["Right Arm"].BrickColor

Hand.Size = Vector3.new(4, 4, 2)

Hand.Anchored = true

Hand.CanCollide = false

Hand.BrickColor = BrickColor.new("Institutional white")

Hand.Material = Enum.Material.Slate

Hand.brickColor = BrickColor.new("Institutional white")

Hand.FormFactor = Enum.FormFactor.Plate

Hand.formFactor = Enum.FormFactor.Plate

SpecialMesh1.Parent = Hand

SpecialMesh1.MeshId = "http://www.roblox.com/asset/?id=32054761"

SpecialMesh1.MeshType = Enum.MeshType.FileMesh

coroutine.wrap(function()

while task.wait() do

Hand.CFrame = Hand.CFrame:Lerp(CFrame.new(mouse.Hit.Position + Vector3.new(0,2,0)) * CFrame.lookAt(hrp.Position,mouse.Hit.Position + Vector3.new(0,3,0)) CFrame.Angles(0,0,math.rad(-180)),0.3)

end

end)()

How do I fix it? Thanks.

Try CFrame.new(mouse.Hit.Position + Vector3.new(0,2,0), hrp.Position) * CFrame.Angles(0,0,math.rad(-180)) instead.

CFrame.lookAt and CFrame.new are same thing, that’s why when I tried both it didn’t do anything.

What im trying to say is that your adding the CFrame of CFrame.lookAt to the position.
This makes it weirdly offset. Using CFrame.new/lookAt directly wont do that issue.

So can I use CFrame.Angles instead?

Well, CFrame.lookAt is setting the position and angle.

For example part.CFrame = CFrame.lookAt( position - sets the position of part, 2nd position - sets the angle of the part )

So you should really just use this, and then offset it with CFrame.Angles

So how do I get only angle from CFrame?

If you just wanna make the hand rotate to your mouse, just do CFrame.new(hand.Position,mouse.Hit.p)
That locks the hand in place, while making it look at your mouse (lookat works too)

But what i really think you should be doing is the code i suggested at first, unless im getting it wrong

Well I need my hand to move with the mouse too I don’t want to lock it.

What do you want the hand to look at? You never made it clear

I wan’t hand to look at the mouse.

Then use the code I said all the way back in the first reply…

It doesn’t do anything! It’s just CFrame.LookAt but old way!

Have you tried it yet? I’m the one using my time trying to help you.

Yes I did! It was same, I tried removing CFrame.new/lookAt and It works as intended, without rotating tho.

Well, your clearly doing something wrong. Goodluck.

I did it EXCATLY like that :

No you didn’t. Replace the first part as well. Make it just the CFrame.new. And also, you swapped hrp.Position and mouse.Hit.Position.

Still didn’t do anything. Just made hand be in HRP and I wan’t hand to MOVE to mouse position, not just look at it.

Thats why i told you to swap hrp.Position and mouse.Hit.Position. Bruh.