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

This if statement won't run?

Asked by 8 years ago

So, I've made a script that checks an AI's health, and if the AI's health is below 700, it's supposed to switch his swords

I've ran the code in the command bar and it worked fine, but whenever I add it into a script, it doesn't execute the if statement (or at least that's what I'm guessing, because once I damage the AI past 700, it doesn't switch swords

It's in a script located inside Workspace

    if game.Workspace.AI.Sword.Humanoid.Health <= 700 then
        game.Workspace.AI.Sword.FireSword:Remove()
        game.Lighting.SecondSword:Clone().Parent = game.Workspace.AI.Sword
    end
1
Can I see the rest of the code please? ItsMeKlc 235 — 8y
0
Make sure the script isn't disabled. GShocked 150 — 8y
0
That's all of it @legokendall ParkwaysV2 5 — 8y

1 answer

Log in to vote
1
Answered by
Hero_ic 502 Moderation Voter
8 years ago

Add a while wait() do.

while wait() do
    if game.Workspace.AI.Sword.Humanoid.Health <= 700 then
            game.Workspace.AI.Sword.FireSword:Remove()
            game.Lighting.SecondSword:Clone().Parent = game.Workspace.AI.Sword
    end
end

if this worked your welcome :) ~KIheros

0
Thank you! ParkwaysV2 5 — 8y
0
You are welcome! :) Hero_ic 502 — 8y
Ad

Answer this question