How can I read terrain voxels to make an oxygen bar?

I wanted to make an oxygen bar using terrain voxels because it would work better since it can detect when your head comes above the water. Someone told me to use terrain voxels but I don’t know how I would script it so that when you go in the water you lose oxygen and when your head comes out of the water you gain oxygen. Can anyone help with reading voxels because I’m quite inexperienced in scripting and idk how I would do this

To help you get in the right direction, it would be very similar to this: Underwater Muffle (Inspired by Polyhex)

You would have to use the CFrame of the player’s head instead of the camera. The rest would involve a function that repeatedly decreases an oxygen variable when underwater and one that repeatedly increases the variable when above water.

Oh yea I see how that works the only problem is I noticed when I test the underwater muffle if I put my camera below the water but my character isn’t underwater the music muffles which is ok for a muffled sound but for an oxygen bar that wouldn’t be good I saw someone do the oxygen bar but they didn’t show how so I don’t know how to make something similar to that