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:

01function countCrates()
02    for i,v in pairs(script.Parent.Shelves:GetChildren()) do
03        local ray = Ray.new(
04                Vector3.new(v.Position),
05                Vector3.new(0,5,0)
06            )
07        local part = workspace:FindPartOnRay(ray)
08        print(v.Name.."Has part on it")
09        print(part)
10    end
11    wait(1)
12end
13 
14 
15countCrates()

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
01function countCrates()
02    for i,v in pairs(script.Parent.Shelves:GetChildren()) do
03        local ray = Ray.new(
04                Vector3.new(v.Position),
05                Vector3.new(0,5,0)
06            )
07        local part = workspace:FindPartOnRay(ray)
08    if part then
09        print(v.Name.."Has part on it")
10        print(part)
11return
12end
13    end
14    wait(1)
15end
16 
17 
18countCrates()
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