Help with type cheking error

I have a script like this.

local currentTarget: Basepart? = nil

if not currentTarget then

local input: Vector3 = (currentTarget.Position - collider.Position).Unit
return nil	

This causes a waring here

local input: Vector3 = (currentTarget.Position - collider.Position).Unit

Type of Basepart? could be nil

I am checkng at the top that Basepart is not nil, however the warning still appears. Is there a way to silence this waring?

There is no Roblox type named ‘Basepart’, the correct name is ‘BasePart’, also you have to typecast the currentTarget variable once you sure it can only be a BasePart:

local input = ((currentTarget :: BasePart).Position - collider.Position).Unit

Also you don’t have to manually specify the type of ‘input’ variable, as its type will be inherited from type of .Unit value of Vector3

1 Like

Thank you!