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?
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()