Need help with the FNAF Power System

Hello, i am making a FNAF game and need some help with my Power System.

So, when i open the cameras it increases the Power Usage by 1, after that the Power system will get the delay according to the Power Usage and wait for delayTime.
If i open and close the cameras fast enough, the system will not drain the power in time because the system is waiting for delayTime, and it will continue draining power slowly even though the cameras are opened. Is there anyway to fix that?

The getWait() function :

local function getWait()
   if Usage.Value == 5 then
   		delayTime = 1.2
   		if plr.leaderstats.Nights.Value == 5 then
   			delayTime = 0.8
   		end
   elseif Usage.Value == 4 then
   		delayTime = 2.3
   		if plr.leaderstats.Nights.Value == 5 then
   			delayTime = 1.5
   		end
   elseif Usage.Value == 3 then
   		delayTime = 3.7
   		if plr.leaderstats.Nights.Value == 5 then
   			delayTime = 2.4
   		end
   elseif Usage.Value == 2 then
   		delayTime = 4.5
   		if plr.leaderstats.Nights.Value == 5 then
   			delayTime = 3
   		end
   elseif Usage.Value == 1 then
   		delayTime = 6
   		if plr.leaderstats.Nights.Value == 5 then
   			delayTime = 4.3
   		end
   elseif Usage.Value == 0 then
   		delayTime = 7.3	
   	if plr.leaderstats.Nights.Value == 5 then
   		delayTime = 5
   	end
   end
end

The While Loop :

	while true do
		wait(.1)
		if game.ReplicatedStorage:WaitForChild("PaidProducts").UnlimitedPower.Value == true then
			while true do
				wait(1)
				PowerLeft.Value = 100
			end
		end
		wait(.1)
			if PowerLeft.Value > 0 then
				getWait()
				drainPower()
				wait(delayTime)
			else
				powerOut()
				wait(7)
				powerout.Volume = 0
				return wait()
		end
	end

The issue is inside the function that increases the power usage when you open the cameras, could you explain more how it works?

Most likely a small delay between being able to open and close cameras would fix the issue, so add that.

1 Like

So when you open the cameras, it will increase your usage by 1, and you wont be able to close your cameras for 1.5 seconds. The power loop gets the wait with getWait() and then waits for delayTime according to your usage. If you open up your cameras WHILE it is waiting to drain your power and then close the cameras in time, the system will not detect if the usage has changed because the loop was waiting for delayTime.

That means that i can spam open and close the cameras to avoid animatronics, such as Freddy and Foxy, and it wont drain my power fast enough. So i can literally pass the night with that

What if instead of changing delaytime you use static delaytime but just increase the amount it drains, for example the delaytime might be 1 second and every time it decreases the amount of power by whatever pace you’d like it to decrease

To explain it more clearly:
powervalue = 100
while task.wait(1) do powervalue -= usage/10 end

It seems that FNAF uses a similar system to this (from what i’ve read on reddit, take it with a grain of salt) and every night there is an additional power usage going on in the background (additional -0.1% every six seconds for night 2, every 5 seconds for night 3, every 4 seconds for night 4, every 3 seconds for night 5 or greater)

i managed to solve it by setting the PowerLeft Value to 999 and then i checked the Usage every second and subtracted the Usage from the PowerLeft value.
And then i just simply used PowerLeft.Value/10 when setting the Text!

Thanks for your help!

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