i was trying to make a script that makes a head and a laser look at you, i got the error 12:25:28.194 - Workspace.TrueBlaster.Head.Script:27: attempt to compare number and nil

Here's the script: local part = script.Parent

function moveTo(target) local dir = (target.Position - part.Position).unit part.BodyGyro.cframe = CFrame.new(0, dir) part.BodyGyro.maxTorque = Vector3.new(9000, 9000, 9000)

part.BodyPosition.position = target.Position part.BodyPosition.maxForce = Vector3.new(10000, 10000, 10000) * part.Speed.Value end

function findNearestTorso(pos) local nearest = { torso = nil, distance = math.inf }

for _, object in ipairs(game.Workspace:GetChildren()) do if object:isA("Model") and object ~= script.Parent then local torso = object:findFirstChild("Torso") local human = object:findFirstChild("Humanoid") if torso and human and human.Health > 0 then local this = { torso = torso, distance = (torso.Position - pos).magnitude } if this.distance < nearest.distance then nearest = this end end end end return nearest.torso, nearest.distance end

while true do local torso = findNearestTorso(part.Position) if torso ~= nil then moveTo(torso) end wait() end

can someone help me fix this?