Even though I have a script to drain the battery, it stays the same.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have asked ChatGPT and tried different methods of a forever loop.
My LocalScript
local Flashlight = script.Parent
local Battery = Flashlight:WaitForChild("Battery")
local Active = false
Flashlight.Equipped:Connect(function()
script.Parent.Enabled = true
end)
Flashlight.Unequipped:Connect(function()
script.Parent.Enabled = false
end)
Flashlight.Activated:Connect(function()
Active = true
end)
Flashlight.Deactivated:Connect(function()
Active = false
end)
task.spawn(function()
while true do
if Active and Battery.Value > 0 then
Battery.Value -= 5
print("Battery:", Battery.Value)
end
task.wait(1)
end
end)
You are setting the value correctly, so I assume this is happening because Active is false. Before the if statement, try printing Active. Also try adding printing something inside the function connected to Activated and Unactivated.
From what I understand, nothing in my script seems to indicate holding down, as it only changes the active variable when the tool is activated or unactivated?