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

Unable to detect if a part is on screen?

Asked by 3 years ago

I have a script that isn't working. And what's funny is that its literally the script copied and pasted from the roblox api reference.

local function isPointVisible(worldPoint)
    local camera = workspace.CurrentCamera
    local vector, onScreen = camera:WorldToViewportPoint(worldPoint)

    if onScreen then
        local origin = camera.CFrame.p
        local ray = Ray.new(origin, worldPoint - origin)
        local hit = workspace:FindPartOnRay(ray)
        if hit then
            return false
        end
    else
        return false
    end
    return true
end
--everything above is copied and pasted from [here](https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint)
local diepartposition = Vector3.new(workspace.Die.Position.X,workspace.Die.Position.Y,workspace.Die.Position.Z)
while true do
    wait()
    local visible = isPointVisible(diepartposition)
    print(visible)
    print(diepartposition)
end

well ,, what prints out is false and then the position repeatedly... but why false?? I'm very very very sure the part is ON my screen and I can see it clearly. But it 's still false. Any idea why? the script isn't working as expected

thanks for your time and i appreciate all help!

Answer this question