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

Attempt to index number with 'HumanoidRootPart' error?

Asked by 1 year ago

I have a code for a tower defense game. Unfortunately. Line 6 in the code below is giving me the error. Below is the code. (yes, there is more code, but this is only the part thats causing trouble)


function FindNearestTarget(newTower) local maxDistance = 15 local nearestTarget = nil for i, target in ipairs(workspace.Mobs:GetChildren()) do print(newTower.HumanoidRootPart.Position) local distance = (target.HumanoidRootPart.Position -newTower.HumanoidRootPart.Position).Magnitude --print(target.Name, distance) if distance < maxDistance then nearestTarget = target maxDistance = distance end end return nearestTarget end

1 answer

Log in to vote
0
Answered by 1 year ago

Nevermind. It was an issue with calling the function later on in the script that provided the problem

Ad

Answer this question