GetPartsObscuringTarget doesn't work

Alright, I am making a horror game and I have a creature called Ghoul that would pop up after you’ve done something.

The problem is the camera ignores every object in the way that’s blocking the camera’s view and proceeds to return 0 as in no objects are obscuring view

This is the code:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local camera = workspace.Camera
local replicatedstorage = game.ReplicatedStorage
local ghoulevent = replicatedstorage.GhoulActivated
local run = game:GetService("RunService")

local lookTime = 0

ghoulevent.OnClientEvent:Connect(function()
   local _, OnScreen
   while wait() do
   	local glass = workspace.WallwithGlass:FindFirstChild("Glass")

   	repeat _,OnScreen = workspace.CurrentCamera:WorldToScreenPoint(workspace.Ghoul.Position)
   		wait()
   	until OnScreen

   	if OnScreen then
   		if #workspace.CurrentCamera:GetPartsObscuringTarget({camera}, {}) == 0 then
   			print(lookTime)
   			lookTime += 0.13
   		end
   	end
   	if lookTime == 5 or lookTime > 5 then
   		ghoulevent:FireServer()
   		break
   	end
   	if game.Workspace.GameEvent.Invaded.Value == true then
   		break
   	end
   end
end)

and here’s a video:

Help? :slight_smile:

1 Like

I think you’re trying to get any objects blocking the cameras view, you can simply do a raycast using workspace:Raycast (not FindOnPartRay). Then just check if the ray is hitting the ghoul or not using Raycast.Instance. Raycast being the object that returns from workspace:Raycast.

1 Like

Doesn’t that ray only cast from the middle like a center dot or a crosshair?

Yes, it does. (dsfDSFDSFDSFFSDDFS)

1 Like