Ok so I have a flashlight script and a battery thing but when I toggle the flashlight on an off continuously then turn it on the frame becomes transparent even faster
local function drainBattery(bool)
if bool == true then
if lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency < 1 and script.flashlight.Value == true and act == true then
print("yes")
repeat
print("truuu")
if lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar4").BackgroundTransparency < 1 then
if lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency < 1 then
BT = lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency
lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency += 0.01
else
bar +=1
end
end
task.wait(timetogone)
until lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar4").BackgroundTransparency > 1
end
end
end
It seems that you’re never registering at the start of the function whether the battery is already going down. Simply make sure only one instance of this function is running at the same time by checking for a boolean that contains whether the function is already running
Yeah, so basically, you need to check whether the function is already running, because you’re running the function everytime you click, but you never stop it from running when it’s clicked the second time (turned off), I would recommend you save whether there is already an instance of the function running before running it again, so you don’t have a duplicate