What's wrong with this script?

Hello, I’m having trouble with this script, it’s supposed to change the ambient color to white and enable a green colorcorrection effect when a key is pressed and a boolean value is off. the Boolean Value is located in ReplicatedStorage and the local script is in StarterCharacterScripts

local UIS = game:GetService("UserInputService")
local RepStorage = game:GetService("ReplicatedStorage")
local nv = RepStorage.NightVisionToggle
local nvBoolean = RepStorage.NightVision
local cd = 2

UIS.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.V and nvBoolean == false then
		print("night vision")
		game.Lighting.OutdoorAmbient = Color3.fromRGB(255,255,255)
		game.Lighting.NightVisionC.Enabled = true
	elseif inputObject.KeyCode == Enum.KeyCode.V and nvBoolean == true then
		print("off")
		game.Lighting.OutdoorAmbient = Color3.fromRGB(75,75,75)
		game.Lighting.NightVisionC.Enabled = false
	end
	if inputObject.KeyCode == Enum.KeyCode.C then
		print("c")
	end
end)

Maybe you forgot to access the value property: nvBoolean.Value == false
Cause seems that you are only checking the existance of the Bool instance and not the Value inside it: nvBoolean == false

local UIS = game:GetService("UserInputService")
local RepStorage = game:GetService("ReplicatedStorage")
local nv = RepStorage.NightVisionToggle
local nvBoolean = RepStorage.NightVision
local cd = 2

UIS.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.V and nvBoolean.Value == false then -- here
		print("night vision")
		game.Lighting.OutdoorAmbient = Color3.fromRGB(255,255,255)
		game.Lighting.NightVisionC.Enabled = true
		
	elseif inputObject.KeyCode == Enum.KeyCode.V and nvBoolean.Value == true then
		print("off")
		game.Lighting.OutdoorAmbient = Color3.fromRGB(75,75,75)
		game.Lighting.NightVisionC.Enabled = false
	end
	if inputObject.KeyCode == Enum.KeyCode.C then
		print("c")
	end
end)

Or maybe you are not setting the nvBoolean.Value to true and false after player press the key:

print("night vision")
game.Lighting.OutdoorAmbient = Color3.fromRGB(255,255,255)
game.Lighting.NightVisionC.Enabled = true
nvBoolean.Value = true
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.