I’m very new to Luau, and is wondering how to script “if I deal an amount of damage to an npc, an event occurs”
This is because I am currently trying to script a game which will give you money when you deal damage to a hostile npc.
I’m very new to Luau, and is wondering how to script “if I deal an amount of damage to an npc, an event occurs”
This is because I am currently trying to script a game which will give you money when you deal damage to a hostile npc.
I’d use a variable to store the current humanoid’s health, use a ‘HealthChanged’ event, check if the humanoid’s health is below the variable’s value, and if so, run code.
Example:
local HP = script.Parent.Health
function Health()
if script.Parent.Health < HP then
-- run code
HP = script.Parent.Health
end
script.Parent.HealthChanged:Connect(Health)
I definitely believe that this function could be slightly improved, but that’s mainly up to you.