I wish to make it so when a player walks under a roof the roof will go invisible and when they go out from under the roof it goes back to being visible, how would I go about doing this effectively. I have tried to use the touched event but I had problems with detecting when the player went out from the roof.
I would probably do it like this:
- In a LocalScript, connect to the
Heartbeatevent of RunService
- Each heartbeat, raycast from the player’s character to the camera.
- If you hit something, and you want that something to be able to dissapear (I suggest tagging those objects with CollectionService), then change its Transparency. You can use TweenService to animate it.
- (edit) Keep track of the last-hit object. If you don’t hit it on the following frame, reset its Transparency to normal.
I would use distance, plus this way you can create a fading effect
Use a touched event on the player’s humanoidrootpart. Make the part invisible in a localscript when the touch starts and visible when the touch ends. This will be the easiest and should work well.
I will definitely be trying this. Thank you.