Hello! So I'm working on a little project, and I made a short script that checks to see if a certain part is within the camera's view. It works and all; however, in the main game, there are parts parented to the player's camera that are also cframed to it. With this being said, I attempted to insert them using table.insert() to Filterdescendantsinstances; however, they are never inserted and thus cause problems. I tried other hacky ways to solve this but none were successful.
Here is the code:
function RayObject(Object) local Ignore = Object:FindFirstChild("Direction").Ignore local RayCastParamsF = RaycastParams.new() RayCastParamsF.FilterType = Enum.RaycastFilterType.Blacklist RayCastParamsF.FilterDescendantsInstances = {Ignore.Value, Character} for i,v in pairs(Camera:GetChildren()) do table.insert(RayCastParamsF.FilterDescendantsInstances, v) --this is what I'm talking about end print(RayCastParamsF.FilterDescendantsInstances) local Unit = (Object.Position-Camera.CFrame.Position).Unit local DotProduct = Unit:Dot(Camera.CFrame.LookVector) local RayResult =game.Workspace:Raycast(Camera.CFrame.Position, Unit*900, RayCastParamsF) local Distance = (Camera.CFrame.Position-Object.Position).Magnitude local CloseDistance = Object:FindFirstChild("Direction"):GetAttribute("CloseDistance") if RayResult then if DotProduct > .63 and RayResult.Instance == Object or Distance <= CloseDistance then return true end end end
Does anyone know why this doesn't work or what I'm doing wrong?