How to enable/disable Night Vision Goggles as keybind?

  1. What do you want to achieve?
    I need you guys to help me edit a bit under this script it works as a Button and can work as device mobile button gui and works when pressing the “N” key bind.
    It looks like crouch Button for device mobiles and computers.
  2. What is the issue?
    I need you guys to help me with how this button gui can work for Computer[Keybind] please? because I can only make it works as a button on the screen, it doesn’t have any short key for night vision goggles so I need your guys to help me with that problem because I still don’t know how to use part code Keybind much(can quite bad) XD
  3. What solutions have you tried so far?
    I was edit it like some videos on Youtube but it isn’t working, if you guys can help edit this script how this can work with mobile and use keybind to enable/disable night vision goggles like other games, thanks.
    [SORRY IF I BAD GRAMMAR]
local button = script.Parent
local nvgscreen = button.Parent.ImageLabel
local toggled = false
local nvgsound = workspace.NightVisionSound

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end
button.Activated:Connect(onButtonActivated)
1 Like

I don’t know the answer to your question, but I have a recommendation. Pleaseeeeeee do not use the “copy paste blockes of code” to change a value thing. Do a little research In loops and tweens to massively shorten your scripts.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input == Enum.KeyCode.E then
		onButtonActivated()
	end
end)

For more help watch this video

And like the other person said, just use tweens bro. Way easier that way

2 Likes

Can you help me add this where it’s and help me please, I don’t know make this, it so hard

Replace this

button.Activated:Connect(onButtonActivated)

with this

UIS.InputBegan:Connect(function(input)
	if input == Enum.KeyCode.E then
		onButtonActivated()
	end
end)

make sure to add the UIS variable at the very top

Like this?

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end
UIS.InputBegan:Connect(function(input)
	if input == Enum.KeyCode.E then
		onButtonActivated()
	end
end)

Yeah don’t forget the

local UIS = game:GetService("UserInputService")

At the top

here, it doesn’t working.
Why? @iATtaCk_Noobsi

local button = script.Parent
local nvgscreen = button.Parent.ImageLabel
local toggled = false
local nvgsound = workspace.NightVisionSound
local UIS = game:GetService("UserInputService")

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end
UIS.InputBegan:Connect(function(input,gameprocess)
	if input == Enum.KeyCode.E then
		onButtonActivated()
	end
end)

Do you have more any ways? it still not working

replace this

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end

with this

local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)

local cc = game.Lighting.ColorCorrection2
local tweeningOn = false

local NightVisionOff = TweenService:Create(cc , info,{Contrast = 0})
local NightVisionOn = TweenService:Create(cc , info,{Contrast = 1})

local function onButtonActivated()
	if tweeningOn == false then
		if cc.Contranst == 0 then
			tweeningOn = true
			NightVisionOn:Play()
			NightVisionOn.Completed:Wait()
			tweeningOn = false
		elseif cc.Contrast == 1 then
			tweeningOn = true
			NightVisionOff:Play()
			NightVisionOff.Completed:Wait()
			tweeningOn = false
		end
	end
end

If you want to learn more about tweening watch this video

It still not working, but thanks you had help me, I will try way to make this or help by another someone

Change

if input == Enum.KeyCode.E then

To

if input.KeyCode == Enum.KeyCode.E then

can you help me edit script a bit please?

local button = script.Parent
local nvgscreen = button.Parent.ImageLabel
local toggled = false
local nvgsound = workspace.NightVisionSound

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end

In what way, Tweening?

World limit

I just need you to help me add a part for key bind to when pressing “e” that script on part " What solutions have you tried so far?" working please

UserInputSerivce.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.E then
		onButtonActivated() 
	end
end)

Just make sure to define UserInputSerivce at the top with your other services.

local UserInputSerivce = game:GetService("UserInputService")

where I should place this or replace?

UserInputSerivce.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.E then
		onButtonActivated() 
	end
end)

on this?

local button = script.Parent
local nvgscreen = button.Parent.ImageLabel
local toggled = false
local nvgsound = workspace.NightVisionSound
local UserInputSerivce = game:GetService("UserInputService")

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end
button.Activated:Connect(onButtonActivated)

Replace

button.Activated:Connect(onButtonActivated)

If you want it to be exclusively a keyBind.
(But if you want both, put it under that Line)

1 Like

Also, if you want, you can make a table with all the steps and the wait times between them, then loop through the table, which makes it easier to edit the script and makes it shorter.

Also use task.wait, as wait is deprecated.

1 Like

Like this?

local button = script.Parent
local nvgscreen = button.Parent.ImageLabel
local toggled = false
local nvgsound = workspace.NightVisionSound
local UserInputSerivce = game:GetService("UserInputService")

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end
button.Activated:Connect(onButtonActivated)
UserInputSerivce.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.E then
		onButtonActivated() 
	end
end)

Screenshot (1514)