Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I use this to see Parts in view?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.