Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

try doing if hp <= 32500 then

0

THX that works!

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.