I have a layout like so:
Model -Script -Shelves --Shelf1,Shelf2, etc..
The script is:
01 | function countCrates() |
02 | for i,v in pairs (script.Parent.Shelves:GetChildren()) do |
03 | local ray = Ray.new( |
04 | Vector 3. new(v.Position), |
05 | Vector 3. 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 ) |
12 | end |
13 |
14 |
15 | countCrates() |
This returns random parts, rather than the crate on each shelf. Why will it not work?
01 | function countCrates() |
02 | for i,v in pairs (script.Parent.Shelves:GetChildren()) do |
03 | local ray = Ray.new( |
04 | Vector 3. new(v.Position), |
05 | Vector 3. 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) |
11 | return |
12 | end |
13 | end |
14 | wait( 1 ) |
15 | end |
16 |
17 |
18 | countCrates() |