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.
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
Event.RBXScriptSignal:Connect(function()
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
end
end)
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
end
end
You can apply the same idea to keeping the door closed and decrementing the currentPhase value until it reaches 1 or 0.