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?