Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I use this to see Parts in view?

Asked by 5 years ago

This always seems to activate even when I'm not looking at the part. I thought it was supposed to only activate if I was looking at the part. How can I use this to activate only when Parts are in view?

local function op()
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA("Part") then
local visible = workspace.CurrentCamera:WorldToScreenPoint(v.Position)
if visible == true then
print(v.Name .. " is visible")
end
end
end
end

game:GetService("RunService").Hearbeat:Connect(op)

1 answer

Log in to vote
0
Answered by
ryan32t 306 Moderation Voter
5 years ago

you need two variables when using WorldToScreenPoint()

local variable,isVisible = workspace.CurrentCamera:WorldToScreenPoint()

the variable is the variable name and isVisible is a boolean value whether it's visible in Camera or not

Ad

Answer this question