Why does humanoid:takedamage() set my hp to NaN?

local debounce = false
local dmgPart = script.Parent -- Inside the part 

dmgPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if not debounce then
			debounce = true
		local char = hit.Parent
		char:WaitForChild("Humanoid"):TakeDamage(25)
			wait(0.2)
			debounce = false
		end
	end
end)

When the part hits me, it sets my health to NaN, making me essentially immortal.
I’ve got no idea why. This just started happening. It was fine b4…

1 Like

Script looks perfectly fine.

Im guessing

  1. Server client differences? I always blame this first.
  2. Try the script in another file, perhaps it is another script causing the issue.

I tried this exact same script and it seems to be working perfectly fine. Are you sure it’s not in a local script?

Is it possible for you to do a live demo video here of you playing it to show us that your health is being set to NaN. Since the alternative is just using Health = Health - number

I’ll try.
:+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1:

robloxapp-20240703-1740497.wmv (2.8 MB)
here is the video.
You can’t see the log but character health is luckily visible.
I simply created a part and a regular script where I pasted your code:
image

Hey there,
I have iframe abilities that give the player a forcefield, so :TakeDamage() is required so it does not bypass forcefields. Natural health regeneration is disabled so I have NO idea how this happens.

I’ll show a video, sure. Just give me a few.

It used to work until recently. I have no idea what changed it as i have no regenerative abilities except for a potion item which I haven’t been using

Hi there,
The only script that interferes health is a health regen stopper.
I will try to remove this and see if damage works normally.

Yes, the issue was said script:

-- Gradually regenerates the Humanoid's Health over time.
-- pwned ur health regen roblox lolololoo
-- put in startercharacterscripts
local REGEN_RATE = 0/0 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = math.huge -- Wait this long between each regeneration step.

--------------------------------------------------------------------------------

local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'

--------------------------------------------------------------------------------

while true do
	while Humanoid.Health < Humanoid.MaxHealth do
		local dt = wait(REGEN_STEP)
		local dh = dt*REGEN_RATE*Humanoid.MaxHealth
		Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
	end
	Humanoid.HealthChanged:Wait()
end

This script changed humanoid’s hp to NaN whenever it was changed.
Deleting it fixed everything. Thank you!

You need to change REGEN_RATE from 0/0 to smth else