The code below is just trying to turn on the SpotLight placed in part but the issue I have is after activating the light and clicking the part once again to turn it off, the script refuses to run the function and does not return any errors in output.
light = script.Parent.SpotLight
charge = script.Parent.Charge.Value
button = script.Parent.ClickDetector
function enable()
if charge >= 100 then
light.Enabled = true
charge = (charge - 20)
print ("on")
print (charge)
elseif light.Enabled == true then
print ("Already on, turning off")
wait (5)
light.Enabled = false
end
end
script.Parent.ClickDetector.MouseClick:connect(enable)

3 comments
Have you checked your charge variable after clicking it the first time?
Right I just noticed that but I've just lowered the value at line 6 but now the issue is that when I click again, instead of turning off after 5 seconds, it just acts as if the part starting at the elseif doesn't exist
Posted a solution based off yours and Ruben's input. Thanks for the assist.