How would I add object values to a part using a raycast?

This is just a quick question. What I want to achieve is to attach(?) a raycast to the player so when the player “looks at a part” (when the raycast touches a part), an object value (or anything like a script or model) is added inside of the part. I also want to remove whatever is added to the part when the player looks away.

I’m not asking for someone to make the script for me. All I want to know is how I could make this

Is this something that could be helpful for you?
https://developer.roblox.com/en-us/api-reference/function/Camera/ScreenPointToRay
I think the best way to check if the mouse is no longer on a part is to put all affected parts in a table and then remove all the parts on the table that are not hit by the next raycast? Just my idea

that could be useful. Also just for clarification, I don’t want the object value (or whatever item) to be added when the mouse is on it. I want the item to be added when the player model is facing towards the part

Ohhh I understand. I believe in that case you could just use the orientation of the head to dictate the orientation of the ray? I haven’t used them in a while so I’m not entirely sure

Create a variable that is used to store the current existing object value that gets up dated every frame, Every frame, you raycast from the player’s humanoid root part using the parts’s .Position as the origin and use the part’s look vector (CFrame.LookVector.Unit*RayLength), and use workspace:Raycast to raycast. Do not use Ray.new and the screen point to ray as mentioned before as they are deprecated, and using deprecated features when there is a replacement is always a bad idea.