Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index number with 'HumanoidRootPart' error?

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.