Replicating bone orientation from client to server--best way?

This code is set up to grab the workspace’s current camera and use it to tell where the player is facing–down, or up. It takes the orientation every 0.1 seconds, and if the orientation has changed, it fires a remote to the server that then takes the camera’s orientation and applies it to a bone in the rig to make the player look up or down. Is this method good practice? Is there any better way to do it? Right now the orientating is a little jagged and rough since it only updates every 0.1 seconds, would there be a way to decrease the interval without increasing possible lag?

Localscript:

local player = game:GetService("Players").LocalPlayer
local cam = workspace.CurrentCamera

local camPosOld = 0
local event = script:WaitForChild("RemoteEvent")

while task.wait(.1) do
	camPosValue = Vector3.new(0,0,0 - (cam.CFrame:ToOrientation() * 40))
	if camPosValue ~= camPosOld then
		event:FireServer(camPosValue)
	end
	camPosOld = camPosValue
end

Script:

local event = script.Parent:WaitForChild("RemoteEvent")
local bone = script.Parent.Parent:WaitForChild("HumanoidRootPart").Bip001['Bip001 Pelvis']['Bip001 Spine']['Bip001 Spine1']['Bip001 Spine2']

event.OnServerEvent:Connect(function(player,pos)
	bone.Orientation = pos
end)

Any feedback is appreciated!

I know some open source modules that do stuff like that. Even if you used something that fires more often than 0.1s, like RenderStepped, it will never be perfectly fluent. I’m not sure if there’s really a point in firing faster, but a way you could make it look more natural would be to Tween the orientation, instead of just setting it.

1 Like

I did try tweening, and maybe it was just the way I was doing it but it didn’t seem as smooth as I wanted it to be. Maybe I’ll try it again later and see how it looks