Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can't detect what the part's name is, in the raycast?

Asked by 4 years ago

My Raycast won't detect what the part's Name is ? - If that makes sense.

01local basePlate = game.Workspace.basePlate
02 
03local rayOrigin = game.Workspace.Part.Position
04 
05local rayDirection = Vector3.new(0,30,0)
06 
07 
08local raycastParams = RaycastParams.new()
09 
10raycastParams.FilterDescendantsInstances = {basePlate}
11raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
12 
13local raycastResults = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
14 
15 
View all 22 lines...

The error code that i'm getting : attempt to index nil with 'Instance'

1 answer

Log in to vote
1
Answered by 4 years ago

A ray is a unitray by default meaning it only extends by one stud. You have to set it’s length by multiplying the direction vector by the length of the ray you want. For example do rayDirection * the length you want. Also wrap the print in an if statement so that it does not error out if it returns nil: if raycastResults then

Ad

Answer this question