Attempt to index nil with 'Density'

I want to read the Density value of a Basepart and if it is under 1, it should do the things below it. For some reason, it gives this error when I try it;

attempt to index nil with 'Density'

Code;

	local touching = script.Parent:GetTouchingParts()

	for i,v in pairs(touching) do
		if v:IsA("BasePart") then
			if v.CustomPhysicalProperties.Density < 1 then
				if not v:FindFirstChild("WaterVelocity") then
					local velocity = script.Parent.WaterVelocity:Clone()
					velocity.Parent = v
					velocity.Position = Vector3.new(v.Position.X,(script.Parent.Size.Y/2)-1,v.Position.Z)
				else
					v.WaterVelocity.Position = Vector3.new(v.Position.X,(script.Parent.Size.Y/2)-1,v.Position.Z)
				end
			end
		end
	end

Its because you are using CustomPhysicalProperties instead of CurrentPhysicalProperties, change it to make it work

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.