Alright, found a useful article on ROBLOX wikia about it. The function FindPartOnRay(ray, ignoreDescendantsInstance); This function searches for parts that would be in the way of the ray that must be defined with a variable before like this:
1 | local ray = Ray.new(Vector 3. new( 5 , 10 , 13 ), |
4 | print (workspace:FindPartOnRay(ray)) |
Then you should check whether the function turns nil. If it does then there is not gonna be anything between the beginning of the ray and the end.
So to solve my problem this would be alright:
02 | local ray 1 = Ray.new(script.Parent.Torso.Position, Vector 3. new( 20 , 0 , 0 )) |
03 | local ray 2 = Ray.new(script.Parent.Torso.Position, Vector 3. new( 0 , 0 , 20 )) |
04 | local ray 3 = Ray.new(script.Parent.Torso.Position, -Vector 3. new( 20 , 0 , 0 )) |
05 | local ray 4 = Ray.new(script.Parent.Torso.Position, -Vector 3. new( 0 , 0 , 20 )) |
06 | while actions = = false and wait( 5 , 15 ) do |
07 | if workspace:FindPartOnRay(ray 1 ) = = nil and workspace:FindPartOnRay(ray 2 ) = = nil and workspace:FindPartOnRay(ray 3 ) = = nil and workspace:FindPartOnRay(ray 4 ) = = nil then |
08 | script.Parent.Humanoid:MoveTo(Vector 3. new(math.random( 0 , 20 ), 0 , math.random( 0 , 20 ))) |