Error attempt to index nil with 'HeadScale'

I don’t understand where the error is here
The script works, but I get this error and the game lags
The script should check if the player has a certain head size and then destroy the module

local Part = script.Parent
local EntireModel = script.Parent:GetDescendants()
local Modle = script.Parent
local db = true

for i,v in pairs(EntireModel) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			if db == true then
				db = false
				if humanoid.HeadScale.Value == 3 then
					db = true
					Modle:Destroy()
				end
			end
		end)
	end
end

You should check to make sure your “humanoid” variable exists. Sometimes it might touch something that doesn’t have a humanoid, so it will error.

You didn’t check if humanoid was an actual thing. If it hit a part that doesn’t have a humanoid then it would be nil. Before your if db == true add if humanoid then