How to make a terrain collision system

Is there a way that players can’t step on the water or climb high ground?

I have tried to make the parts invisible but it is not very efficient and very consuming and I would like to know if there is any way to do it with a script.

An example of what I want to achieve
image

i think there is script that create barier above or under any terrain material u choose

but i might be not sure

Can you tell me where I see it or could you provide it to me?
I just need an example.