Forwarding cframe to server

I am firing remote event to the server which will fire the position to all clients in order to update the player’s head cframe and rotation

Client:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateNeck = ReplicatedStorage:WaitForChild("UpdateNeck")
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer

-- Function to handle neck tracking for a given character
local function trackNeck(character)
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	local humanoid = character:WaitForChild("Humanoid")

	local isR15 = humanoid.RigType == Enum.HumanoidRigType.R15
	local neck
	if isR15 then
		neck = character:FindFirstChild("Neck", true)
	else
		local torso = character:WaitForChild("Torso")
		neck = torso:FindFirstChild("Neck")
	end

	if not neck then return end

	local initialNeckC0
	if isR15 then
		neck.C1 = CFrame.new(0, 0, 0) -- Set C1 to 0,0,0 for R15
		initialNeckC0 = neck.C0 -- Keep the original C0
	else
		neck.C1 = CFrame.new(0, -0.5, 0)
		initialNeckC0 = CFrame.new(0, 1, 0)
	end

	local smoothFactor = 0.1
	local lastUpdateTime = tick() -- Initialize the last update time

	game:GetService("RunService").RenderStepped:Connect(function()
		if neck and humanoidRootPart then
			local cameraDirection = humanoidRootPart.CFrame:ToObjectSpace(camera.CFrame).LookVector

			local targetC0 = CFrame.new(0, initialNeckC0.Y, 0) 
				* CFrame.Angles(0, -cameraDirection.X, 0) 
				* CFrame.Angles(cameraDirection.Y, 0, 0)

			neck.C0 = neck.C0:Lerp(targetC0, smoothFactor)

			-- Send the updated neck positions to the server every second
			if tick() - lastUpdateTime >= 1 then
				UpdateNeck:FireServer(neck.C0, neck.C1)
				lastUpdateTime = tick() -- Update the last update time
			end
		end
	end)
end

if player.Character then
	trackNeck(player.Character)
end

player.CharacterAdded:Connect(trackNeck)

local TweenService = game:GetService("TweenService")

-- Listen for neck updates from the server
UpdateNeck.OnClientEvent:Connect(function(neckC0, neckC1, sender)
	if sender ~= player then  -- Only update if the sender is not the local player
		local character = sender.Character
		if character then
			local isR15 = character:FindFirstChild("Humanoid").RigType == Enum.HumanoidRigType.R15
			local neck
			if isR15 then
				neck = character:FindFirstChild("Neck", true)
			else
				local torso = character:FindFirstChild("Torso")
				neck = torso:FindFirstChild("Neck")
			end

			if neck then
				local tweenInfo = TweenInfo.new(0.35, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
				local tweenC0 = TweenService:Create(neck, tweenInfo, { C0 = neckC0 })
				local tweenC1 = TweenService:Create(neck, tweenInfo, { C1 = neckC1 })
				
				tweenC0:Play()
				tweenC1:Play()

				-- Optional: Connect to tween completed event if you need to perform actions after tweening
				tweenC0.Completed:Connect(function()
					-- Do something after C0 tween completes if needed
				end)

				tweenC1.Completed:Connect(function()
					-- Do something after C1 tween completes if needed
				end)
			end
		end
	end
end)

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateNeck = ReplicatedStorage:WaitForChild("UpdateNeck")

UpdateNeck.OnServerEvent:Connect(function(player, neckC0, neckC1)
	-- Send the neck update to all clients, including the sender
	UpdateNeck:FireAllClients(neckC0, neckC1, player)
end)

It updates every 1 second, but this probably isnt a correct way so any help or recommendations will help in regard of how to optimize this

This isnt the wrong way to do this and i dont think it needs optimization if its fired once a second?
if you however need optimization you dont need to send a Whole CFrame data with position (i dont think you use the position) and rotation and limit to rotation only, which is like, 3 numbers lol

Yes its ok if i fire it once a second buuut it looks unsmooth on client side for other players, that’s why I set the remote to fire every 0.1 second and that’s the problem. i dont know whether itll mess up the server resources? if there is multiple players the count goes up

Well yea limit it to rotation and compress it all in a table, maybe even use buffers idk there is a quadzillion data compression methods

using tick() is unnecessary if you are not using the precision of it

it can be replaced with:

local lastUpdateTime = os.time() -- Initialize the last update time

	game:GetService("RunService").RenderStepped:Connect(function()
		if neck and humanoidRootPart then
			local cameraDirection = humanoidRootPart.CFrame:ToObjectSpace(camera.CFrame).LookVector

			local targetC0 = CFrame.new(0, initialNeckC0.Y, 0) 
				* CFrame.Angles(0, -cameraDirection.X, 0) 
				* CFrame.Angles(cameraDirection.Y, 0, 0)

			neck.C0 = neck.C0:Lerp(targetC0, smoothFactor)

			-- Send the updated neck positions to the server every second
			if os.time() ~= lastUpdateTime then -- If the last time is not the same as not(time has changed)
				UpdateNeck:FireServer(neck.C0, neck.C1)
				lastUpdateTime = os.time()
			end
		end
	end)

this does mean that cause its os.time itll be synced so all characters will tween their head at the same time. Because it is only 1 second and your animation is 0.35 seconds you will have a period of 0.65 seconds where the character(local and others) will not rotate their head.