Make sure the tip of the Pencil is screwed on securely and snugly ( NOT TOO tight! ).
Then follow all of the troubleshooting tips in this Apple Website Webpage support article.
Tap the link below.
https://support.apple.com/en-us/HT205236
Also, have you checked the tip of your Pencil lately?
Does it look worn? On the tip, can you see though it, somewhat, and see the metal sensor/transducer tube through the Pencil tip?
Apple has a 4 pack of replacement tips for purchase.
Found here.
Tap the link below.
https://www.apple.com/shop/product/MLUN2AM/A/apple-pencil-tips-4-pack
Best of Luck to You!