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
Nevermind. It was an issue with calling the function later on in the script that provided the problem