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

4 comments
Add an if statement. if Alive~=true then
Well it should already.... if Alive.Value == false then it will stop the loop and move on
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 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.