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

How do i get the npc to walk faster when his health hits a certain number?

Asked by 4 years ago

I need him to walk at walk speed 15 when his hp gets to 32500 and i dont know why this script wont work can somebody pls help (i put it in his humanoid)

function rage()
    local hp = script.Parent.Health
    if hp <32500 then
    script.Parent.WalkSpeed = 15    

    end
end
script.Parent.Health.HealthChanged:Connect(rage)
0
try doing `if hp <= 32500 then` User#23252 26 — 4y
0
THX that works! coolmanHDMI 72 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You're doing "script.Parent.Health.HealthChanged"

It should actually be

function rage()
    local hp = script.Parent.Health
    if hp <32500 then
    script.Parent.WalkSpeed = 15    

    end
end
script.Parent.HealthChanged:Connect(rage)

.HealthChanged is a function that is used on the humanoid, not on the Health value.

https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged

Also, if you plan on making it so the walkspeed changes at 32500, you should make it

if hp =< 32500 then

instead of

if hp < 32500 then

Using the latter would result in the script changing only when the health is less than 32500, in comparison to being equal to or less than.

Ad

Answer this question