Code to change game brightness not working

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…

2 Likes

Other than Connect not being captialized, is there any errors? Additionally I would move the stopper or its useless.

local stopper = 0

script.Parent.Touched:connect(function()
if stopper == 0 then
game.Lighting.Brightness = 0
wait(15)
game.Lighting.Brightness = 1
stopper =  1
end
end)

Use :Connect instead of :connect.

Stopper is used as debounce. I will try out the Connect instead of connect thing

what exactly isn’t working?
30 CH

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)

Okay, not debounce, but you can only touch it once, bad wording on my part

This should do it then.

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)

Upon looking into the issue, I’m having a problem. It activates as soon as I join the game…

The Function can trigger by touching another part, you need to add an if statement to ensure the touching part is a humanoid.

1 Like

Or I make it not touch another part

Thanks, it worked, however is there a way to blackout the sky (sky is seen through a window)