How to make your own healthChanged OOP style

So Im making an OOP Health system for my inanimate objects in game but the thing is I want them to have health, but Im not sure how to check when the healthChanges

Current code :

local inanimate = {}
inanimate.__index = inanimate


function inanimate.new(obj,health)
	local object = {}
	
	object.Health = health
	object.Character = obj
	
	return setmetatable(object, inanimate)
end

function inanimate:HealthChanged(newHealth)
	-- not sure
end



return inanimate

The health will change when something wants to change it.

Ex: A sword attacks a bush. The sword can call said bush’s HealthChanged function either directly or indirectly how you set this up.

I personally would go mad trying to find a decent way for any object to reference another object without a big lookup table, so I suggest using BindableEvents for this. So, when a sword attacks a bush, it will fire the given bush’s bindable, telling it that it has been attacked with said amount of damage.

1 Like

Oh alright I see what your saying, thanks this is what I needed!