Humanoid.HealthChanged Firing too many times

to keep it simple, I need this to fire but only once, it fires an extra time per times I’ve previously fired it. Heres the snippit of code that matters here


		if db == false then
			db = true
			db = false
			return true;

One possible cause could be that the default “Health” script constantly heals the player. So you might want to make a custom Health script.

db in your excerpt is declared in a scope local to the function. Have you tried declaring it globally first?

local db: boolean

    if db then return end
    db = true
    -- some code
    db = false
    return true

If you only need HealthChanged to fire once you can use :Once over :Connect (this will disconnect the event after the event has fired once).

If the event is firing when you don’t expect it to a likely cause is the default Health regen script as mentioned by SchlossGarage. You can disable the health regen by placing an empty script called “Health” in StarterPlayer.StarterCharacterScripts.

Fix was really simple, I had this inside of an event scope. Whoops!

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