So, I’m trying to make a pathfinding AI, however, it just errors “attempt to index nil with ‘position’ and I don’t know how I could fix it.”
Have you tried printing root_part to see if anything is there?
yes, I’ve even tried printing the position. It prints the position, and it prints the root part.
workspace:Raycast
requires a Instance to not return nil, you would need to add an if
statement to check if it was a success:
local Result = workspace:Raycast() -- lets say there is code here
if Result then -- if Raycast was a Success
Could be wrong tho, let me know if so, rn i do not have the time to check.
Either root_part or My_Root is nil, judging by the output it has to be root_part. You’re sure you printed root_part inside of the check_sight function? I need to see how you’re calling check_sight, could you show your full script?
Workspace:Raycast doesn’t take any instance parameters. It takes 2 vectors and a RaycastParams
Im not saying it requires an Instance parameter, im saying it needs to hit (or intersect) an Instance to not return nil
that was provided in the code, the “result = workspace:raycast” is the line of code that provides the error
Is your root in the blacklisted table?
How is root_Part
passed as an argument in the function?
it’s passed as a part(the humanoidrootpart of the player that it’s supposed to chase)