How do I detect if a player's camera is under a part

I’m trying to create a rain system similar to Bloxburg’s, how it works is when your camera is under something (for example a part) the rain GUI goes away, then if your camera is not under a part it appears again.

How am I supposed to detect if a player’s camera is under a part?

I used Raycasting for my system; fire a ray upwards from the Player’s camera and if it hits something then it’s under something, if not then its under nothing.

Also you’ve listed this under the incorrect category.

1 Like

My bad, I’ve changed the topic and thanks I’ll look into that

1 Like

I’ve made this script which seems to not work, I’ve tried creating 2 parts with the same positions and it was done as expected, do you know what I did wrong?

local raycastParam = RaycastParams.new()
raycastParam.FilterType = Enum.RaycastFilterType.Blacklist

local camera = workspace.CurrentCamera
local raycastResult = workspace:Raycast(camera.CFrame.Position, camera.CFrame.Position + Vector3.new(0, 100, 0))

while wait(3) do
    if raycastResult then
        print(raycastResult.Instance:GetFullName())
    else 
        print("none")
    end
end

(It was printing none even though my camera was under something)

I’ve added the raycastParam to the last param but it still didn’t work

Ah I placed the raycastResult outside of the while wait that’s why it didn’t work, fixed now.

Cast a ray from the character’s root’s negative up vector.

You’re firing your ray once here:

local raycastResult = workspace:Raycast(camera.CFrame.Position, camera.CFrame.Position + Vector3.new(0, 100, 0))

Put this inside your while loop, additionally you can use RunService instead of a while loop to make it update quicker.