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

How would I make this loop stop when a value changes?

Asked by
SuperFryX 130
9 years ago

I am making a Boss that will randomly choose an attack, basically, I want this loop to detect when the Alive value is no longer true and start the death function. However, with this script, when it has 0 health it waits until it finishes an attack before doing the death function which isn't how it is supposed to work. Basically, the instant the Alive Value is false, I want it to stop what it is doing and play its death animation, and I have no idea how to.

This is the main part of the script, the attacks are usually 5 to 10 seconds so its really awkward when the Boss is at 0 health and he hasn't died until after he finishes attacking.

while Alive.Value==true do
    wait(2.5)
        FireSequence()--A missile firing sequence that takes a couple seconds
        wait(2.5)
    RanChoice=math.random(1,5)
    if RanChoice==1 then
        print"FLAMETHROWER"
        Flame()--A flame throwing sequence that takes a couple seconds
    elseif RanChoice==2 then
        laser()--A laser shooting  sequence that takes a couple seconds
        wait(1)
        Move()--Moves the boss
    else
        Move()
    end
end
print"DEAD" 
Death()--This is supposed to activate when Alive.Value==false

0
Add an if statement. if Alive~=true then SimplyRekt 413 — 9y
0
Well it should already.... if Alive.Value == false then it will stop the loop and move on NinjoOnline 1146 — 9y
0
Maybe you could have another script that detects death. It would delete the script that handles the attacks and then run the death animation. aquathorn321 858 — 9y
0
@aquathorn321 If I recall correctly, disabling a script doesn't fully stop a while true do loop, you have to use a break command or something. I'll try this though. SuperFryX 130 — 9y

2 answers

Log in to vote
-1
Answered by 9 years ago

Yes, this script it fine it is because the Waits inside of the "While true do" part So basically It has to wait the 2.5 seconds to start the loop over and until it starts the loop over it wont see that the Alive Value is false do you read me?

Ad
Log in to vote
-1
Answered by 9 years ago

Put your loop in a function, put the function inside a loop wich will check if the Alive value is true or not ( and don't forget the wait inside the main loop ).

Answer this question