‹ Back to My Code
systems lua
local DamageSystem = {}

function DamageSystem.ApplyDamage(humanoid, amount)
	if not humanoid or humanoid.Health <= 0 then
		return
	end

	humanoid:TakeDamage(amount)

	if humanoid.Health <= 0 then
		humanoid.Died:Once(function()
			print(humanoid.Parent.Name .. " has died")
		end)
	end
end

function DamageSystem.Heal(humanoid, amount)
	if not humanoid then
		return
	end

	humanoid.Health = math.min(humanoid.MaxHealth, humanoid.Health + amount)
end

return DamageSystem