3rd camera arm movement to mouse

Hello currently I have errors with my script.
Whenever the person lags, it causes the arm to move weird.

How do you replicate the lag?
By pressing alt+s inside studio going to network settings, and replicating the lag.

Game File

I need fix.rbxl (47,4 KB)

Server Script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player: Player, direction: Vector3,neck,neckc,shoulder,shoulderc)
	if direction.Magnitude > 1 then -- Invalid direction vector
		return
	end
	neck.C0 = neckc
	shoulder.C0 = shoulderc
end)

Local Script

local RunService = game:GetService("RunService")
local localPlayer = game.Players.LocalPlayer

RunService.RenderStepped:Connect(function()
	local character = game.Players.LocalPlayer.Character
	if character==nil then
		return
	end
	local head: BasePart = character:FindFirstChild('Head') :: any
	local torso: BasePart = character:FindFirstChild('Torso') :: any
	local rootPart: BasePart = character:FindFirstChild('HumanoidRootPart') :: any
	if not torso or not head or not rootPart then
		return
	end

	local neck: Motor6D = torso:FindFirstChild('Neck') :: any
	local waist: Motor6D = rootPart:FindFirstChild('RootJoint') :: any
	local rightShoulder: Motor6D = torso:FindFirstChild('Right Shoulder') :: any
	local rightHip: Motor6D = torso:FindFirstChild('Right Hip') :: any
	local leftHip: Motor6D = torso:FindFirstChild('Left Hip') :: any
	if not neck or not waist or not rightShoulder or not rightHip or not leftHip then
		return
	end

	local directionFromOrigin
	local mouse = localPlayer:GetMouse()
	directionFromOrigin = (mouse.Hit.Position - mouse.Origin.Position).Unit

	local mouseDirection = torso.CFrame.Rotation:PointToObjectSpace(directionFromOrigin)
	rightShoulder.Transform = CFrame.new()



	local targetShoulder: CFrame = CFrame.new(rightShoulder.C0.Position)
		* CFrame.Angles(0, -math.asin(mouseDirection.X), 0)
		* CFrame.Angles(math.asin(mouseDirection.Y), 0, 0)
		* CFrame.Angles(math.pi / 2, math.pi / 2, 0)
		* CFrame.new(0, 0, 0)

	rightShoulder.C0 = rightShoulder.C0:Lerp(targetShoulder, 0.25)

	local targetNeck: CFrame = CFrame.new(neck.C0.Position)
		* CFrame.Angles(0, -math.asin(mouseDirection.X), 0)
		* CFrame.Angles(math.asin(mouseDirection.Y) * 0.5, 0, 0)
		* CFrame.Angles(math.pi / 2, math.pi, 0)

	neck.C0 = neck.C0:Lerp(targetNeck, 0.25)


		local mouse = localPlayer:GetMouse()
		directionFromOrigin = (mouse.Hit.Position - mouse.Origin.Position).Unit

			game.ReplicatedStorage.RemoteEvent:FireServer(directionFromOrigin,neck,neck.C0,rightShoulder,rightShoulder.C0)
end)

Found solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.