Can't change Fog End through script

Hello! I am trying to change the Fog End property of lighting through a script but it doesn’t work. No errors.

Here is the script:

local debounce = false
local lighting = game:GetService("Lighting")

script.Parent.Touched:Connect(function(hit)
	if debounce == false then
		debounce = true
		
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			wait(0.5)
			
			game.Workspace.Bedroom.Radio["Happy Song"]:Stop()
			
			game.Workspace.Bedroom.InvisWall.Transparency = 0
			game.Workspace.Bedroom.InvisWall.CanCollide = true
			game.Workspace.Bedroom.Door:Destroy()
			
			wait(1)
			
			for i,bulb in pairs(game.Workspace.Hallways.Bulbs.Working:GetChildren()) do
				bulb.Model.Bulb.PointLight.Brightness = 0
				bulb.Model.Bulb.LightsOut:Play()
				wait(0.2)
			end
			
			wait(0.5)
			lighting.FogEnd = 10
			game.SoundService.LightsOut:Play()
		end
	end
end)
1 Like

Its because your setting debounce to true when it touches something but not the player so you should move it here

local debounce = false --Also ypu can change this to db its way faster to type
local lighting = game:GetService("Lighting")

script.Parent.Touched:Connect(function(hit)
	if debounce == false then
		
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
debounce = true
			wait(0.5)
			
			game.Workspace.Bedroom.Radio["Happy Song"]:Stop()
			
			game.Workspace.Bedroom.InvisWall.Transparency = 0
			game.Workspace.Bedroom.InvisWall.CanCollide = true
			game.Workspace.Bedroom.Door:Destroy()
			
			wait(1)
			
			for i,bulb in pairs(game.Workspace.Hallways.Bulbs.Working:GetChildren()) do
				bulb.Model.Bulb.PointLight.Brightness = 0
				bulb.Model.Bulb.LightsOut:Play()
				wait(0.2)
			end
			
			wait(0.5)
			lighting.FogEnd = 10
			game.SoundService.LightsOut:Play()
		end
	end
end)

1 Like