So I am trying to make when the flashlight value is off the tweeting of the color stops but even after I disable the script it still works
local LocalPlayer = game:GetService(“Players”).LocalPlayer;
local bar = 1
local lp = game.Players.LocalPlayer
local function drainBattery(bool)
if bool == true then
while wait(0/1) do
if lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency < 1 then
print("yes")
for i = 0, 1, 0.01 do
local uiiElement = lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar)
local startColor = Color3.new(1, 1, 1)
local endColor = Color3.new(1, 0, 0)
local fadeDuration = 10
local tweenInfo = TweenInfo.new(fadeDuration, Enum.EasingStyle.Linear)
local tween = game:GetService("TweenService"):Create(uiiElement, tweenInfo, {BackgroundColor3 = endColor})
tween:Play()
script.Parent.flashlight.Changed:Connect(function(val)
if val == false then
local d = lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar):Clone()
lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar):Destroy()
tween:Destroy()
d.Parent = lp.PlayerGui.FlashLight.BatteryF.Bar
end
end)
LocalPlayer.PlayerGui.RemoteEvent.OnClientEvent:Connect(function()
tween:Cancel()
bar = 1
for i, v in pairs(LocalPlayer.PlayerGui.FlashLight.BatteryF.Bar:GetChildren()) do
v.BackgroundTransparency = 0
v.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
end
end)
if lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar4").BackgroundTransparency < 1 then
lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency += 0.01
if lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency > 1 then
if bar ~= 4 then
bar +=1
end
end
if bar == 4 and lp.PlayerGui.FlashLight.BatteryF.Bar:FindFirstChild("Bar"..bar).BackgroundTransparency > 1 then
script.flashlight.Value = false
end
end
wait(.1)
end
end
end
end
end
script.Parent.flashlight.Changed:Connect(function(val)
if val == true then
drainBattery(true)
print(“tr”)
else
drainBattery(false)
end
end)