So, Im making a part that when I click it it subtracts one from a variable. The click detector should work until it hits 0, and I get no errors on this part and it works fine besides for when I click it to subtract.
local clickdetector = game.Workspace["Forest Cavern"].PuzzleOne.ClickDetector
local bricklife = 10
if bricklife > 0 then
clickdetector.MouseClick:Connect(function()
local bricklife = bricklife - 1
print(bricklife)
end)
end
Heres the code I have written. What happens is, the bricklife starts as ten, then I click it and the bricklife prints 9 in the output, but when I click it again it prints 9 again, and doesnt go down. I clicked it 20 times and it still printed nine, showing its not just something wrong with the print statement. How do I make it so it continually subtracts?

2 comments
Ok, The first part is solved, but now if bricklife is 0 or lower it doesnt stop
ok, so here is the second part of the fix