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