Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.