local g=game.Lighting.ExposureCompensation local p local J local I local w local k local R local K local W function removehelmet()if plr.Character then if R then R:Disconnect()end animating=false togglenvg(false)actionservice:UnbindAction("\110\118\103\116\111\103\103\108\101")if I then I:Destroy()end if W then W:Destroy()end end end function oncharadded(G)(G:WaitForChild("\072\117\109\097\110\111\105\100")).Died:connect(function()removehelmet()end)G.ChildAdded:connect(function(G)local z if G.Name=="\072\101\108\109\101\116"then W=G I=Instance.new("\083\099\114\101\101\110\071\117\105")I.IgnoreGuiInset=true z=Instance.new("\084\101\120\116\066\117\116\116\111\110")z.Text="\072\101\108\109\101\116"z.Size=UDim2.new(.05,0,.035,0)z.TextColor3=Color3.new(.75,.75,.75)z.Position=UDim2.new(.1,0,.3,0)z.BackgroundTransparency=.45 z.BackgroundColor3=Color3.fromRGB(124,52,38)z.Font=Enum.Font.SourceSansBold z.TextScaled=true z.MouseButton1Down:connect(removehelmet)z.Parent=I I.Parent=plr.PlayerGui R=G.AncestryChanged:Connect(function(g,p)if not p then removehelmet()end end)end local a=G:WaitForChild("\085\112",.5)if a then p=a k=require(p:WaitForChild("\065\085\084\079\095\067\079\078\070\073\071"))K=p:WaitForChild("\078\086\071\095\083\101\116\116\105\110\103\115")local R=Instance.new("\073\109\097\103\101\076\097\098\101\108")R.BackgroundTransparency=1 R.ImageTransparency=1 local W=R:Clone()W.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047"..K.OverlayImage.Value W.Size=UDim2.new(1,0,1,0)W.Name="\079\118\101\114\108\097\121"local G=K.RemoveButtonPosition.Value z.Position=UDim2.new(G.X,0,G.Y,0)R.Name="\078\111\105\115\101"R.AnchorPoint=Vector2.new(.5,.5)R.Position=UDim2.new(.5,0,.5,0)R.Size=UDim2.new(2,0,2,0)W.Parent=I R.Parent=I local S=k.tweeninfo local function Z(g,p)if p then for p,J in pairs(p)do table.insert(g,J)end end end J=k.onanim w=k.offanim on_overlayanim={tweenservice:Create(game.Lighting,S,{ExposureCompensation=K.Exposure.Value}),tweenservice:Create(colorcorrection,S,{Brightness=K.OverlayBrightness.Value;Contrast=.8,Saturation=-1,TintColor=K.OverlayColor.Value}),tweenservice:Create(I.Overlay,S,{ImageTransparency=0}),tweenservice:Create(I.Noise,S,{ImageTransparency=0})}off_overlayanim={tweenservice:Create(game.Lighting,S,{ExposureCompensation=g}),tweenservice:Create(colorcorrection,S,{Brightness=0,Contrast=0;Saturation=0;TintColor=Color3.fromRGB(255,255,255)}),tweenservice:Create(I.Overlay,S,{ImageTransparency=1});tweenservice:Create(I.Noise,S,{ImageTransparency=1})}actionservice:BindAction("\110\118\103\116\111\103\103\108\101",function()togglenvg(not nvgactive)return Enum.ContextActionResult.Pass end,true,Enum.KeyCode.N)end end)end plr.CharacterAdded:connect(oncharadded)local G=workspace:FindFirstChild(plr.Name)if G then oncharadded(G)end function playtween(g)spawn(function()for g,p in pairs(g)do if typeof(p)=="\110\117\109\098\101\114"then wait(p)else p:Play()end end end)end function applyprops(g,p)for p,J in pairs(p)do g[p]=J end end function cycle(g)local p=I.Noise local J=g.src local w repeat w=J[math.random(1,#J)]until w~=g.last p.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047"..w local k=math.random(230,255)p.Position=UDim2.new(math.random(.4,.6),0,math.random(.4,.6),0)p.ImageColor3=Color3.fromRGB(k,k,k)g.last=w end function togglenvg(g)if not animating and p then nvgevent:FireServer()I.TextButton.Visible=not g animating=true nvgactive=g if k.lens then k.lens.Material=g and"\078\101\111\110"or"\071\108\097\115\115"end if g then playtween(J)delay(.75,function()playtween(on_overlayanim)spawn(function()while nvgactive do cycle(k.dark)cycle(k.light)wait(.05)end end)animating=false end)else playtween(w)delay(.5,function()playtween(off_overlayanim)animating=false end)end end end nvgevent.OnClientEvent:connect(function(g,p)local J=g:WaitForChild("\116\119\105\115\116\106\111\105\110\116")local I=require(g.AUTO_CONFIG)local w=I.lens if w then w.Material=p and"\078\101\111\110"or"\071\108\097\115\115"end playtween(I[p and"\111\110\097\110\105\109"or"\111\102\102\097\110\105\109"])end)local z=game.Lighting local a=game.ReplicatedStorage local S=a:WaitForChild("\069\110\097\098\108\101\065\117\116\111\076\105\103\104\116\105\110\103")if S.Value then function llerp(g,p,J)return g*(1-J)+p*J end local g=(a:WaitForChild("\077\105\110\066\114\105\103\104\116\110\101\115\115")).Value local p=(a:WaitForChild("\077\097\120\066\114\105\103\104\116\110\101\115\115")).Value local J=(a:WaitForChild("\077\105\110\065\109\098\105\101\110\116")).Value local I=(a:WaitForChild("\077\097\120\065\109\098\105\101\110\116")).Value local w=(a:WaitForChild("\077\105\110\079\117\116\100\111\111\114\065\109\098\105\101\110\116")).Value local k=(a:WaitForChild("\077\097\120\079\117\116\100\111\111\114\065\109\098\105\101\110\116")).Value function setdaytime()local R=z.ClockTime local K=math.abs(R-12)local W=1-K/12 z.Brightness=llerp(g,p,W)z.Ambient=J:lerp(I,W)z.OutdoorAmbient=w:lerp(k,W)end;(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:connect(setdaytime)end
--//DEFAULT VALUES

local defexposure = game.Lighting.ExposureCompensation

local nvg
local onanim
local gui
local offanim
local config
local onremoved
local setting
local helmet

function removehelmet()
	if plr.Character then
		if onremoved then
			onremoved:Disconnect()
		end
		animating = false
		togglenvg(false)
		actionservice:UnbindAction("nvgtoggle")
		if gui then
			gui:Destroy()
		end
		if helmet then
			helmet:Destroy()
		end
	end
end

function oncharadded(newchar)
	newchar:WaitForChild("Humanoid").Died:connect(function()
		removehelmet()
	end)
	newchar.ChildAdded:connect(function(child)
		local removebutton
		if child.Name == "Helmet" then
			helmet = child
			gui = Instance.new("ScreenGui")
			gui.IgnoreGuiInset = true

			removebutton = Instance.new("TextButton")
			removebutton.Text = "Helmet"
			removebutton.Size = UDim2.new(0.05, 0, 0.035, 0)
			removebutton.TextColor3 = Color3.new(0.75, 0.75, 0.75)
			removebutton.Position = UDim2.new(0.1, 0, 0.3, 0)
			removebutton.BackgroundTransparency = 0.45
			removebutton.BackgroundColor3 = Color3.fromRGB(124, 52, 38)
			removebutton.Font = Enum.Font.SourceSansBold
			removebutton.TextScaled = true
			removebutton.MouseButton1Down:connect(removehelmet)

			removebutton.Parent = gui
			gui.Parent = plr.PlayerGui

			onremoved = child.AncestryChanged:Connect(function(_, parent)
				if not parent then
					removehelmet()
				end
			end)
		end
		local newnvg = child:WaitForChild("Up", 0.5)
		if newnvg then
			nvg = newnvg
			config = require(nvg:WaitForChild("AUTO_CONFIG"))
			setting = nvg:WaitForChild("NVG_Settings")

			local noise = Instance.new("ImageLabel")
			noise.BackgroundTransparency = 1
			noise.ImageTransparency = 1

			local overlay = noise:Clone()
			overlay.Image = "rbxassetid://" .. setting.OverlayImage.Value
			overlay.Size = UDim2.new(1, 0, 1, 0)
			overlay.Name = "Overlay"

			local buttonpos = setting.RemoveButtonPosition.Value
			removebutton.Position = UDim2.new(buttonpos.X, 0, buttonpos.Y, 0)

			noise.Name = "Noise"
			noise.AnchorPoint = Vector2.new(0.5, 0.5)
			noise.Position = UDim2.new(0.5, 0, 0.5, 0)
			noise.Size = UDim2.new(2, 0, 2, 0)

			overlay.Parent = gui
			noise.Parent = gui

			local info = config.tweeninfo

			local function addtweens(base, extra)
				if extra then
					for _, tween in pairs(extra) do
						table.insert(base, tween)
					end
				end
			end

			onanim = config.onanim
			offanim = config.offanim

			on_overlayanim = {
				tweenservice:Create(game.Lighting, info, { ExposureCompensation = setting.Exposure.Value }),
				tweenservice:Create(
					colorcorrection,
					info,
					{
						Brightness = setting.OverlayBrightness.Value,
						Contrast = 0.8,
						Saturation = -1,
						TintColor = setting.OverlayColor.Value,
					}
				),
				tweenservice:Create(gui.Overlay, info, { ImageTransparency = 0 }),
				tweenservice:Create(gui.Noise, info, { ImageTransparency = 0 }),
			}

			off_overlayanim = {
				tweenservice:Create(game.Lighting, info, { ExposureCompensation = defexposure }),
				tweenservice:Create(
					colorcorrection,
					info,
					{ Brightness = 0, Contrast = 0, Saturation = 0, TintColor = Color3.fromRGB(255, 255, 255) }
				),
				tweenservice:Create(gui.Overlay, info, { ImageTransparency = 1 }),
				tweenservice:Create(gui.Noise, info, { ImageTransparency = 1 }),
			}

			actionservice:BindAction("nvgtoggle", function()
				togglenvg(not nvgactive)
				return Enum.ContextActionResult.Pass
			end, true, Enum.KeyCode.N)
		end
	end)
end

plr.CharacterAdded:connect(oncharadded)

local oldchar = workspace:FindFirstChild(plr.Name)
if oldchar then
	oncharadded(oldchar)
end

function playtween(tweentbl)
	spawn(function()
		for _, step in pairs(tweentbl) do
			if typeof(step) == "number" then
				wait(step)
			else
				step:Play()
			end
		end
	end)
end

function applyprops(obj, props)
	for propname, val in pairs(props) do
		obj[propname] = val
	end
end

function cycle(grain)
	local label = gui.Noise
	local source = grain.src
	local newframe
	repeat
		newframe = source[math.random(1, #source)]
	until newframe ~= grain.last
	label.Image = "rbxassetid://" .. newframe
	local rand = math.random(230, 255)
	label.Position = UDim2.new(math.random(0.4, 0.6), 0, math.random(0.4, 0.6), 0)
	label.ImageColor3 = Color3.fromRGB(rand, rand, rand)
	grain.last = newframe
end

function togglenvg(bool)
	if not animating and nvg then
		nvgevent:FireServer()
		gui.TextButton.Visible = not bool
		animating = true
		nvgactive = bool
		if config.lens then
			config.lens.Material = bool and "Neon" or "Glass"
		end
		if bool then
			playtween(onanim)
			delay(0.75, function()
				playtween(on_overlayanim)
				spawn(function()
					while nvgactive do
						cycle(config.dark)
						cycle(config.light)
						wait(0.05)
					end
				end)
				animating = false
			end)
		else
			playtween(offanim)
			delay(0.5, function()
				playtween(off_overlayanim)
				animating = false
			end)
		end
	end
end

nvgevent.OnClientEvent:connect(function(nvg, activate)
	local twistjoint = nvg:WaitForChild("twistjoint")
	local config = require(nvg.AUTO_CONFIG)
	local lens = config.lens
	if lens then
		lens.Material = activate and "Neon" or "Glass"
	end
	playtween(config[activate and "onanim" or "offanim"])
end)

local lighting = game.Lighting
local rs = game.ReplicatedStorage

local autolighting = rs:WaitForChild("EnableAutoLighting")

if autolighting.Value then
	function llerp(a, b, t)
		return a * (1 - t) + b * t
	end

	local minbrightness = rs:WaitForChild("MinBrightness").Value
	local maxbrightness = rs:WaitForChild("MaxBrightness").Value
	local minambient = rs:WaitForChild("MinAmbient").Value
	local maxambient = rs:WaitForChild("MaxAmbient").Value
	local minoutdoor = rs:WaitForChild("MinOutdoorAmbient").Value
	local maxoutdoor = rs:WaitForChild("MaxOutdoorAmbient").Value

	function setdaytime()
		local newtime = lighting.ClockTime
		local middaydiff = math.abs(newtime - 12)
		local f = (1 - middaydiff / 12)
		lighting.Brightness = llerp(minbrightness, maxbrightness, f)
		lighting.Ambient = minambient:lerp(maxambient, f)
		lighting.OutdoorAmbient = minoutdoor:lerp(maxoutdoor, f)
	end

	game:GetService("RunService").RenderStepped:connect(setdaytime)
end
