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

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

2 answers

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

3 comments

0

Id suggest using the HealthChanged humanoid event rather than the while loop https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged

0

oki i used the varibles because i thought it would go for the stats of the humanoid

0

your script didn't work it's walkspeed stayed the same

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

4 comments

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

0

i thought only local scripts can use local not normal scripts but it seems cool to me

0

nope, local meens only in this script, but local scripts can use localplayer

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.

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