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

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

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

0

Add an if statement. if Alive~=true then

0

Well it should already.... if Alive.Value == false then it will stop the loop and move on

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.

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.

2 answers

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?

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 ).

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