ToObjectSpace not using

Hello, I am making an FPS gun system, I am currently working on the aiming system, but for some reason it is not working, here is my code:

[image]

RunService.RenderStepped:Connect(function()
if FPSArms then

	-- 📌 Kamera hareketine göre dönüş açısını hesapla (sway)
	local rot = camera.CFrame:ToObjectSpace(lastCameraCF)
	local X, Y, Z = rot:ToOrientation()

	-- 📌 Silahın sallanmasını düzgün hesapla
	swayCF = swayCF:Lerp(CFrame.Angles(-X * currentSwayAMT, -Y * currentSwayAMT, 0), 0.1)
	lastCameraCF = camera.CFrame		

	-- 📌 Yeni silah pozisyonunu hesapla
	local nc = aimCF * swayCF * CFrame.new(0, -3, 0)

	-- 📌 Silahı kameraya uygun şekilde taşı
	for _, v in pairs(camera:GetChildren()) do
		if v:IsA("Model") then
			v:PivotTo(camera.CFrame * nc)
		end
	end

	-- 📌 Nişan alırken doğru ofseti kullan
	if Aim then
		local offset = GunModel.PrimaryPart.CFrame:ToObjectSpace(GunModel.AimPart.CFrame)
		aimCF = aimCF:Lerp(offset:Inverse(), 0.1)
		currentSwayAMT = aimSwayAMT
	else
		aimCF = aimCF:Lerp(CFrame.new(), 0.05)
		currentSwayAMT = swayAMT
	end
end

end)

Idle
image

Aiming
image

AimPart
image

Change to #help-and-feedback:scripting-support,

Keep all your posts in 1 post please, not multiple

1 Like

Must be how your script is written, I use ObjectSpace and it works fine.

It’s simpler to use AttachmentPoints instead of Parts for this since they’re already using ObjectSpace for CFrames.