Fix NaN Stats [B42.13-B42.18+]

If you liked this item, please rate it up on Steam Workshop page.

Author: Afyrmo

Last revision: 14 May at 12:17 UTC

File size: 208.71 KB

On Steam Workshop

Description:
Compatibility: Build 42.13 → 42.18+ (SP/MP)

Fix NaN Stats automatically detects when gameplay values become corrupted as NaN (Not-a-Number) or Infinity and safely restores them to valid values — preventing broken moodles/HUD bars, “temperature/wetness = NaN” issues, pain/health glitches, and other weird behavior caused by invalid numbers.


What this mod does

Sometimes a value can become NaN or Infinity due to a bug, a mod interaction, or an edge case. Once a value is invalid, many systems stop behaving correctly.

This mod is a lightweight safety net:

  • Detects invalid numbers (NaN, +Inf, -Inf) in stats, nutrition, pain/health sources, thermoregulation, and worn clothing.
  • Repairs only values that are actually invalid (it does not change normal values).
  • Runs automatically while you play.
  • Optional on-screen + log notifications when something is fixed (Mod Options).

When should you use it?

Use this mod if you notice any of these symptoms:

  • A stat/moodle looks “stuck”, behaves strangely, or never updates correctly.
  • You use status-bar HUD mods (e.g. Simple Status, Modern Status) and one of the displayed bars shows weird/blank values, freezes, or behaves incorrectly.
  • The Debug UI shows nan or an invalid value for a stat, nutrition value, temperature, wetness, pain, or a clothing-related field.
  • You get the “body temperature = NaN” / “wetness = NaN” type of bug (especially noticeable during winter runs).
  • You suspect a mod or an edge case caused numeric corruption.

You can keep it enabled permanently, or enable it temporarily to repair a save and disable it again afterward.


What it fixes
Character stats

The mod checks every CharacterStat and repairs any value that becomes invalid.

Common examples include: Hunger, Thirst, Fatigue, Endurance, Fitness, Drunkenness, Anger, Pain, Panic, Morale, Stress, Boredom, Unhappiness, Sanity, Comfort, Wetness, Temperature, Health, ColdStrength, Sickness, etc.

Nutrition
  • Calories
  • Carbohydrates
  • Lipids (Fats)
  • Proteins
  • Weight (fallback reset if needed)
Pain / health sources (BodyParts / BodyDamage)
  • Repairs invalid numbers in BodyPart/BodyDamage fields that can cause global Pain to snap back to invalid values.
  • Repairs BodyPart wetness and pain sources (plus related timers/fields when present).
  • If a BodyPart’s Health becomes NaN, it is restored to 100 to prevent corruption loops.
  • Repairs OverallBodyHealth (General Debuggers → Body) when it becomes invalid.
Thermoregulation (temperature/wetness)
  • Recovers from “body temperature = NaN”.
  • Recovers from “wetness = NaN” (including per-body-part wetness).
  • Scans Thermoregulator thermal nodes and performs a safe reset/update when needed.
  • Includes BodyPart wetness recovery to prevent invalid-number feedback loops.
Worn clothing values (when they become invalid)
  • Insulation (invalid → restored to a safe/script default)
  • Wind Resistance (invalid → restored to a safe/script default)
  • Clothing/item wetness
  • Blood level
  • Dirtiness

Notifications (optional)

If enabled in Mod Options, the mod can display a small message over the character (and also write a log line) when it fixes something.

This helps you notice when a specific action or mod interaction produced an invalid value.

Example:

Fix NaN: Temp/Wetness | Clothing x4 (Insulation/Wind) | Stats: Thirst | Nutrition: Calories

Multiplayer notes
  • Works in Singleplayer and Multiplayer (hosted/dedicated).
  • For MP, the mod should be enabled on the server so fixes are server-authoritative and clients stay in sync.

Performance / resource usage

Very low. The mod performs lightweight checks at a fixed interval and only writes values when something is actually invalid. During normal gameplay (with no NaNs/Infs), it effectively does nothing.


Safe to add / safe to remove
  • Safe to add to an existing save: it only repairs corrupted values.
  • Safe to remove: it does not add items, recipes, maps, or permanent content.
  • It simply prevents and repairs invalid-number corruption while enabled.

Notes
  • This mod is a “sanity fixer”: it does not attempt to diagnose the root cause, only to restore valid, playable values.
  • If you consistently get NaNs/Infs, consider checking mod conflicts and reporting details (build number + mod list + steps to reproduce).

Planned improvements

Possible future updates may include:

  • Configurable check frequency
  • Custom reset values (per stat)

Credits
  • Afyrmo — Original author and main maintainer (Fix NaN Stats)
  • Kaori — Helpful investigation, reproduction notes, and contributions that improved the 42.15+ fixes (thanks!)

More mods & feedback

You can find my other Project Zomboid mods here

If you find Fix NaN Stats useful, please consider leaving a thumbs up and adding it to your favorites — it helps other players discover it.

Feedback and suggestions are always welcome.

Workshop ID: 3627071412
Mod ID: FixNaNStats