Alright so, I am making a boss system. There is a loop that goes through three attacks that the boss performs. I want it so that once the boss is dead, the attacks end. The problem is that a while ___ do
loop only checks the ___
at the end of each loop. I want it so that even if the boss is half way through an attack, he will stop in his tracks, so that I can do something like a death cinematic.
BASICALLY, I want to stop a loop on the event of the boss dying, and it needs so stop everything it’s doing, and return the boss to an idle.
Here’s what I was trying to do:
local function waitWithCheck(length)
for i = 0, length/0.1 do
task.wait(0.1)
if boss.Health.current.Value == 0 then return true end
end
return false
end
-- behaviour loop
local function gameLoop()
print("loop")
while true do
if waitWithCheck(5) then break end
voidRun()
if waitWithCheck(5) then break end
cry()
if waitWithCheck(5) then break end
throwTrash()
end
hum.Health = 0
end
-- on event
repeat task.wait() until script.start.Value == true
print("recieved")
gameLoop()
This works a little bit, instead of using task.wait()
inbetween attacks, I made a function that continues to check the boss health, and then breaks the function. The problem with this is that if the boss is midway through an attack, it wont be able to break the loop until the next waitWithCheck()
.
Any help at all, is appreciated!