Custom Health module (with humanoid-like health)

Here’s a custom Humanoid module for when you need just the Health, no movement, names, etc.

Just put this module on anything and add an int variable called Health and MaxHealth and you can require this module from anywhere

You connect to it’s Died and HealthChanged events normally, just like a humanoid, but if you need to read the Health and MaxHealth you need to add a .Value to read the number, not the value instance.

Also run the .init function before you do anything, to activate it

If you know how to make it better let me know)

local module = {}


--Create the variables
function module.init()
	
	module.Health = script.Health

	module.MaxHealth = script.MaxHealth
	
	
	died = Instance.new("BindableEvent")
	module.Died = died.Event
	
	local healthChanged = Instance.new("BindableEvent")
	module.HealthChanged = healthChanged.Event
	
	
	module.Health.Changed:Connect(function()
		
		healthChanged:Fire(module.Health.Value)
		
		if module.Health.Value < 1 then
			
			died:Fire()
		end
	end)
	
end


function module:TakeDamage(n)
	
	module.Health.Value -= n
	
	if module.Health.Value < 1 then
		died:Fire()
	end
	
end


return module
2 Likes

This sounds more like a Health module than a Humanoid module to me :thinking:

5 Likes

Hmm ur right, I was just thinking in these terms coz it mimics the humanoid