Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there an alternative to the HealthChanged event?

Asked by 5 years ago

I'm creating a bit of a "bleeding" script, and i'm looking for the script to fire every time the target takes damage. Currently, the script fires until the target reaches max health. I'm guessing this is something to do with health regen? Here's the block of code, i'm still pretty new to scripting, and if there's any better way out there I would be deeply greatful. Here's the enclosed function:

Definition:

local function damage(severity,lethality)
    script.Parent.Rate = severity
    if humanoid.Health > 0 then
    wait(0.5)
    else
    script.Parent.Rate = 0
    script.Parent.Size = NumberSequence.new(lethality)
    end
end

Called:

humanoid.HealthChanged:Connect(function()
    damage(12,0.1)
end)

1 answer

Log in to vote
0
Answered by
lunatic5 409 Moderation Voter
5 years ago

Yes. I believe you can use GetPropertyChangedSignal() (https://www.robloxdev.com/api-reference/function/Instance/GetPropertyChangedSignal). Your code would look something like the following:

player:GetPropertyChangedSignal("Health"):Connect(function()
    --code
end)
Ad

Answer this question