How can I detect what the camera is colliding with?

I am creating a Free model Portable Water part that actually lets you swim in it, with even a custom swimming animation and everything. but I need to detect that the camera is colliding with the water part itself to create a underwater effect.

Any help how I can do this?

Create a part and set it’s CFrame to the camera CFrame. Weld it, and then use a .Touched event or a Region3 and then use the rest of your code. Be sure to make it’s size something that is appropriate and isn’t too big or too small. Just try to make something that feels good, lots of fine-tuning will probably be needed

I can’t seem to find the player camera position trough scripts

I select the part that is supposed to be the camera part but, it does not move on client side?

On a normal script, I typed in:

while true do
script.Parent.CFrame = workspace.Camera.CFrame

As far as my knowledge goes, you can’t access the camera through a server script. You’d need to do it on the client. Don’t worry about server replication, since the effect will only be for the local player

I tried with both a normal and a local script, and none are making the part move to the actual players camera

The local script does not move anything, the normal script only moves the part to the free camera that happens when you click to server side

A RenderStepped event might be better for this. You can just continuously set the part’s CFrame to the camera’s CFrame. You should put the local script somewhere inside of the player or player character, such as StarterCharacterScripts or StarterGui because that’s what lets you access most client-sided things.

You could also Raycast using the Camera’s position:

--LocalScript I'm assuming
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local CamPos = Camera.CFrame.Position
local RayDirection = Camera.CFrame.LookVector

RunService.RenderStepped:Connect(function()
    local Result = workspace:Raycast(CamPos, RayDirection)

    if Result then
        print("Camera is intersecting part: "..Result.Instance)
    end
end)

You’d have to update the CamPos variable each frame or else it will just raycast where the camera started but that could work as well.