-- Rotates the arms, waist, and neck to make the aiming for more realistic

RE_UpdateSpine.OnServerEvent:Connect(function(player, theta)
	if player.Character then
		
		local humanoid = player.Character.Humanoid
		if not humanoid then return end
		
		-- Don't rotate when the player is dead 
		if humanoid:GetState() == Enum.HumanoidStateType.Dead then return end
		
		local neck = player.Character.Head.Neck
		local waist = player.Character.UpperTorso.Waist
		local leftArm = player.Character.LeftUpperArm.LeftShoulder
		local rightArm = player.Character.RightUpperArm.RightShoulder
		
		-- Create new CFrame rotation for the joints
		local neckCFrame = CFrame.fromEulerAnglesYXZ(theta*0.5,0,0)
		local waistCFrame = CFrame.fromEulerAnglesYXZ(theta*0.5,0,0)
		local leftArmCFrame = CFrame.fromEulerAnglesYXZ(theta*0.25,0,0)
		local rightArmArmCFrame = CFrame.fromEulerAnglesYXZ(theta*0.25,0,0)
		
		-- Apply rotations
		neck.C0 = Neck_CFrame * neckCFrame
		waist.C0 = Waist_CFrame * waistCFrame
		leftArm.C0 = Left_Upper_Arm_CFrame * leftArmCFrame
		rightArm.C0 = Right_Upper_Arm_CFrame * rightArmArmCFrame
	end
end)
