I have been making a game that has been my best yet. I have some code that had been failing. Here is the code (There are multiple variants of this that still aren’t working).
local stopper = 0
script.Parent.Touched:connect(function()
if stopper == 0 then
game.Lighting.Brightness = 0
wait(15)
game.Lighting.Brightness = 1
end
end)
stopper = stopper + 1
I am happy to add clarification, this is driving me insane…
If you want a debounce this code should work. Your previous code would never run since when the code runs stopper has a value of 1 and the touched event’s if statament looked for a value of 0.
local debounce = false
script.Parent.Touched:Connect(function()
print("Touched")
if not debounce then
debounce = true
print("Stopper is equal to 0")
game.Lighting.Brightness = 0
print("Brightness 0")
wait(15)
game.Lighting.Brightness = 1
print("Brightness 1")
debounce = false
end
end)
local touched = false
script.Parent.Touched:Connect(function()
print("Touched")
if not touched then
touched = true
print("Stopper is equal to 0")
game.Lighting.Brightness = 0
print("Brightness 0")
wait(15)
game.Lighting.Brightness = 1
print("Brightness 1")
end
end)