Hello there developers and I hope you are having a good day! I have made a simple item spawning system with the min and max XYZ coordinates and it works great however I am unsure on how I can stop this system from spawning through walls. I was thinking I could detect this using the RayCast I made but any help is deeply appreciated!
local Part = workspace.Bed:Clone()
Part.Parent = workspace
local RandomPosition = Vector3.new(math.random(-175,155),19,math.random(-30,170))
local Raytoground = Ray.new(RandomPosition,Vector3.new(0,-10000,0))
local PartOnRay,PositionOnRay= workspace:FindPartOnRay(Raytoground)
if PartOnRay and PositionOnRay then
Part:PivotTo(CFrame.new(PositionOnRay))
end