Player arm and head following mouse cursor on serverside

I have a fully functional client-side script that makes the player’s right arm and head follow their mouse cursor, however I want to make this server-sided and I have no idea how to do so. My idea was to use remotes but that would kill the server performance and be way too spammy. Please provide me with an alternative and/or help me convert this to work on the server-side. Here is my current code in a LocalScript inside of the StarterPlayerScripts folder

local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Neck = Head:WaitForChild("Neck")
local Arm = Character:WaitForChild("RightUpperArm")
local Shoulder = Arm:WaitForChild("RightShoulder")
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local NeckOriginC0 = Neck.C0
local ShoulderOriginC0 = Shoulder.C0

Neck.MaxVelocity = 1/3

RunService.RenderStepped:Connect(function()
	local CameraCFrame = Camera.CoordinateFrame
	
	if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then

		local ArmLookVector = Arm.CFrame.lookVector
		local HeadPosition = Head.CFrame.p
		
		if Neck and Shoulder then
			if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then

				local Point = PlayerMouse.Hit.p
				local Distance = (Head.CFrame.p - Point).magnitude
				local Difference = Head.CFrame.Y - Point.Y

				Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance) ), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
				Shoulder.C0 = Shoulder.C0:lerp(ShoulderOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)
			end
		end
	end
end)
2 Likes

you could make a serversided script that tweenservices the neck.C0 and the shoulder.c0 firing like remote:FireServer(motor,motor.C0) and the serversides make the Motor.C0 = c0val or use tweenservice (im bad at scripting)