How to make a progressing enemy

I am trying to recreate a system similar to Nightmare Foxy in Five Nights at Freddy 4.

In short, there are 4 phases that foxy can go up to, and once he passes the 4th phase you die. You can hold the door closed to make him go back a phase.

I made a similar system, but its slow and inefficiant, is there a good way to go at this?

You can just store an integer representing the current phase of the enemy:

local currentPhase = 1

and read from the variable at specific points and do something:

-- Example trigger to detect the current phase the enemy is in
   if currentPhase == 1 then
      --... do something at the first phase
   elseif currentPhase == 2 then
      --... do something at the second phase
   elseif currentPhase == [number] then
      --... and so on

If you want the enemy to progress over time, you can use a loop to slowly progress the phases:

while condition1 do -- doesn't need to be a loop, this is just an example
   task.wait(int) -- amount of time to increment the phase
   if condition2 then -- check if the player isn't doing anything to halt the progression of the phases (such as the player keeping the door shut)
       currentPhase += 1 -- proceed to the next phase

You can apply the same idea to keeping the door closed and decrementing the currentPhase value until it reaches 1 or 0.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.