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

How to return if a part is on a shelf using FindPartOnRay?

Asked by
Asigkem 32
8 years ago

I have a layout like so:

Model -Script -Shelves --Shelf1,Shelf2, etc..

The script is:

function countCrates()
    for i,v in pairs(script.Parent.Shelves:GetChildren()) do
        local ray = Ray.new(
                Vector3.new(v.Position),
                Vector3.new(0,5,0)
            )
        local part = workspace:FindPartOnRay(ray)
        print(v.Name.."Has part on it")
        print(part)
    end
    wait(1)
end


countCrates()

This returns random parts, rather than the crate on each shelf. Why will it not work?

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
function countCrates()
    for i,v in pairs(script.Parent.Shelves:GetChildren()) do
        local ray = Ray.new(
                Vector3.new(v.Position),
                Vector3.new(0,5,0)
            )
        local part = workspace:FindPartOnRay(ray)
    if part then
        print(v.Name.."Has part on it")
        print(part)
return
end
    end
    wait(1)
end


countCrates()

0
That wasn't my problem, I meant why does it say there is no part? Even when there is a part directly on it? Asigkem 32 — 8y
Ad

Answer this question