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?
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
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!