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

How to make an NPC go faster on low health?

Asked by 3 years ago
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

Log in to vote
0
Answered by 3 years ago

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 23 — 3y
0
oki i used the varibles because i thought it would go for the stats of the humanoid dylancrazy88 20 — 3y
0
your script didn't work it's walkspeed stayed the same dylancrazy88 20 — 3y
Ad
Log in to vote
0
Answered by
xxaxxaz 42
3 years 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 2647 — 3y
0
i thought only local scripts can use local not normal scripts but it seems cool to me dylancrazy88 20 — 3y
0
nope, local meens only in this script, but local scripts can use localplayer xxaxxaz 42 — 3y
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 42 — 3y

Answer this question