(HELP)How can I make an NPC's walkspeed increases when damaged

HELP NEEDED - NPC walkspeed increases when damaged.
I have a humanoid zombie npc with default walkspeed and 100 health. I am trying to find out how to make a script where every 20 damage the zombie takes, the walkspeed goes up by one. Is this possible and if so, could somebody help me figure something out.

1 Like

Make a value for the zombie health, then make a script (probably inside the zombie would be fine, but serverscriptservice is probably going to lag less if you make it a loop) then do if healthvalue < 100 then or fill in your selfchosen number then just use script.Parent.walkspeed = amount for the walkspeed

1 Like

There are definitely better alternatives as compared to what I am about to draft out, but if it’s just 100 HP then this will be fine. You could do something like:

local humanoid = game.Workspace.Zombie.Humanoid
while humanoid do
    if humanoid.Health <= 80 and humanoid.Health > 60 then
        humanoid.WalkSpeed = 17
    elseif humanoid.Health <= 60 and humanoid.Health > 40 then
        humanoid.WalkSpeed = 18
    elseif humanoid.Health <= 40 and humanoid.Health > 20 then
        humanoid.WalkSpeed = 19
    elseif humanoid.Health <= 20 and humanoid.Health > 0 then
        humanoid.WalkSpeed = 20
    end
end

Yes it is very repetitive and again there are better alternatives, but this is what I would do if I didn’t want to think too much.

2 Likes

That’s basically what I said above lol

I know, and thank you for saying it. However based on the fact that he is asking the question, I assume that he is less experienced in this field so I thought it would be nice to write out a little draft (not the full script) so that it would save him time. And next time, he would know how to do it himself.

Yeah, I prefer to just tell them approximitely, and if they ask further then tell them

Thank you for this, this has actually solved my problem! I really appreciate it and thanks for helping me learn something new!

1 Like

No worries! Also you may want to mark the appropriate post as a solution (for the current and upcoming topics you start) when they are solved, so that other community members do not need to click on it and attempt to solve the issue. :smile: