0

# How to make an NPC go faster on low health?

Minor = script.Parent
Health = script.Parent
WalkSpeed = script.Parent
if Health <= 900 then
script.Parent.Minor.WalkSpeed = 39
end


i'm trying to make a script that makes it so when an NPC hits low health it goes fast but for some reason it doesn't work when i set it to the said value that is supposed to make it go fast when the health reaches that value also i named the Humanoid "Minor" so don't get confused on why it says minor = script.parent lol

0

What? Why are all your variables script.Parent ...

if script.Parent.Minor.Health <= 900 then
script.Parent.Minor.WalkSpeed = 39
end


This is enough, no need for those variables. If you want it to constantly check how much health it has then...

while true do
wait()
if script.Parent.Minor.Health <= 900 then
script.Parent.Minor.WalkSpeed = 39
end
end

0
Id suggest using the HealthChanged humanoid event rather than the while loop https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged enzotinman1 22 — 4d
0
oki i used the varibles because i thought it would go for the stats of the humanoid dylancrazy88 20 — 3d
0
your script didn't work it's walkspeed stayed the same dylancrazy88 20 — 3d
0
xxaxxaz 38
4 days ago

dont forget your locals and the script must only be in the Model unless if you know how to change this code.

local Humanoid = script.Parent
local Health = Humanoid.Health
local WalkSpeed = Humanoid.WalkSpeed
if Health <= 900 then
WalkSpeed = 39
end

0
that doesnt solve the problem, you can use global variables as well. the linter will pick it up and underline it. so this should be a comment greatneil80 2465 — 3d
0
i thought only local scripts can use local not normal scripts but it seems cool to me dylancrazy88 20 — 3d
0
nope, local meens only in this script, but local scripts can use localplayer xxaxxaz 38 — 3d
0
local scripts are scripts that only the player can use, normal scripts are for all players and the server to see. but local code is in all scripts, it is the best way to name a value unless if you need a global witch this one dosn't need a global. xxaxxaz 38 — 3d