How to make my night vision goggles not visible in first person?

Thank you for being here and for your assistance! I would like to make my Night Vision goggles invisible if the player is in first person, and vice versa if they are in third person. Of course, this visibility change should only affect the client’s view.

Here’s my current progress:

Explorer:
image

MainServer Script:

local Tool = script.Parent
local Queso = true

local Handle = script.Parent:WaitForChild("Goggles1")


Tool.ToolTip = "Night Vision [OFF]"

Tool.Activated:Connect(function()
	local Player = script.Parent.Parent
	if Queso == true then
		Queso = false
		Tool.ToolTip = "Night Vision [ON]"
		if Player:FindFirstChild("Goggles1")==nil then
			local Goggles1 = Handle:Clone()
			local BackAttachment = Instance.new("Attachment")
			BackAttachment.Axis = Vector3.new(0,0,0) --change to (0,-1,-1) if you want it on the torso's front [MEDIO 60]
			BackAttachment.Name = "WaistAttachment3"
			BackAttachment.Parent = Goggles1
			Goggles1.Parent = Player
			Goggles1.Name = "Googles1"
			Goggles1.CanCollide = false
			Goggles1.Transparency = 0
			Goggles1.Anchored = false
			local Torso = Player:FindFirstChild("Head")
			if Torso then
				local w=Instance.new("Motor")
				w.Part0=Goggles1
				w.Part1=Torso
				w.C0=BackAttachment.CFrame+Vector3.new(0,0,0)
				w.Parent=Goggles1
			end
		end
	else
		Tool.ToolTip = "Night Vision [OFF]"
		Player:FindFirstChild("Googles1"):Remove()


		Queso = true
	end
end)

MainClient Script:

script.Parent.NVE.Parent = game.Lighting
local NVE = game.Lighting:WaitForChild("NVE")
local Tool = script.Parent
local Queso = true
local Player = script.Parent.Parent
local Goggles = Player:FindFirstChild("Goggles1")

Tool.Activated:Connect(function()
	if Queso == true then
		Queso = false
		NVE.Enabled = true
	else
		NVE.Enabled = false
		Queso = true
	end
end)

local function IsInFirstPerson()
    if game.Players.LocalPlayer.CameraMinimumZoomDistance <= 0.5 then
	    Goggles.Transparency = 1
    else
	    Goggles.Transparency = 0
    end
end

while true do
	wait(0.1)
	IsInFirstPerson()
end

Thank you for taking the time to read this, and I hope someone can help me with this issue! :slight_smile:

6 Likes

By local script you can either make the goggles transparent or put them in a temporary place until they leave 1st person.

4 Likes

But how to detect player is in first person

4 Likes

You could check the distance between the camera and the player’s head, if it is less than 0.5, its likely the player is in 1st person.

4 Likes

In the client script I tried to do what you just said and it didn’t work

3 Likes

Can you show the script that you wrote?

3 Likes
script.Parent.NVE.Parent = game.Lighting
local NVE = game.Lighting:WaitForChild("NVE")
local Tool = script.Parent
local Queso = true
local Player = script.Parent.Parent
local Goggles = Player:FindFirstChild("Goggles1")

Tool.Activated:Connect(function()
	if Queso == true then
		Queso = false
		NVE.Enabled = true
	else
		NVE.Enabled = false
		Queso = true
	end
end)

local function IsInFirstPerson()
    if game.Players.LocalPlayer.CameraMinimumZoomDistance <= 0.5 then
	    Goggles.Transparency = 1
    else
	    Goggles.Transparency = 0
    end
end

while true do
	wait(0.1)
	IsInFirstPerson()
end
3 Likes

This is client, but bruh, i wrotted the scripts in the desc of this forum

3 Likes

try this

local function isInFirstPerson()
    local cameraPosition = camera.CFrame.Position
    local headPosition = player.Character and player.Character:FindFirstChild("Head") and player.Character.Head.Position
    
    if cameraPosition and headPosition then
        local distance = (cameraPosition - headPosition).Magnitude
        return distance < 0.5 
    end
    
    return false
end
3 Likes

My NV System is in a tool, I say it so you don’t get complicated with the character

3 Likes

I don’t know what Locals to use there and I don’t know exactly where to write what happens if the player is in first person, basically, can you make it a little more complete please?

3 Likes

Sure,

local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera

local function isInFirstPerson()
    local cameraPosition = camera.CFrame.Position
    local headPosition = player.Character and player.Character:FindFirstChild("Head") and player.Character.Head.Position
    
    if cameraPosition and headPosition then
        local distance = (cameraPosition - headPosition).Magnitude
        return distance < 0.5
    end
    
    return false
end

if isInFirstPerson() then
    print(true)
else
    print(false)
end
1 Like

You will need to run function whenever camera position changes, unless you get a better way to implement the functions.

2 Likes

when the player goes into first person the head transparency becomes 1 so use this :

Head:GetPropertyChangedSignal('LocalTransparencyModifier'):Connect(function()
		if Head.LocalTransparencyModifier == 1 then
	    	 Goggles.Transparency = 1
		else
	         Goggles.Transparency = 0
		end
end)

Or if you want the goggles to have the same effect as the head where transparency fades as you zoom do :

Head:GetPropertyChangedSignal('LocalTransparencyModifier'):Connect(function()
		 Goggles.Transparency = Head.LocalTransparencyModifier 
end)
3 Likes

It does not works…

Main Client:

script.Parent.NVE.Parent = game.Lighting
local NVE = game.Lighting:WaitForChild("NVE")
local Tool = script.Parent
local Queso = true
local Player = script.Parent.Parent
local PlayerHead = Player.Head
local Goggles = Player:FindFirstChild("Goggles1")

Tool.Activated:Connect(function()
	if Queso == true then
		Queso = false
		NVE.Enabled = true
	else
		NVE.Enabled = false
		Queso = true
	end
end)

3 Likes

It does not work…

Main Client:

script.Parent.NVE.Parent = game.Lighting
local NVE = game.Lighting:WaitForChild("NVE")
local Tool = script.Parent
local Queso = true
local Player = script.Parent.Parent
local PlayerHead = Player.Head
local Goggles = Player:FindFirstChild("Goggles1")

Tool.Activated:Connect(function()
	if Queso == true then
		Queso = false
		NVE.Enabled = true
	else
		NVE.Enabled = false
		Queso = true
	end
end)

local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera

local function isInFirstPerson()
	local cameraPosition = camera.CFrame.Position
	local headPosition = player.Character and player.Character:FindFirstChild("Head") and player.Character.Head.Position

	if cameraPosition and headPosition then
		local distance = (cameraPosition - headPosition).Magnitude
		return distance < 0.5
	end

	return false
end

if isInFirstPerson() then
	print(true)
	Goggles.Transparency = 1
else
	print(false)
	Goggles.Transparency = 0
end

2 Likes

Is the googles a meshpart or a model ?

2 Likes

Have you tried putting it in an run service loop? Like BindToRenderStep? You are only checking as soon as the player joins, you should be checking multiple times

2 Likes

:tired_face:

script.Parent.NVE.Parent = game.Lighting
local NVE = game.Lighting:WaitForChild("NVE")
local Tool = script.Parent
local Queso = true
local Player = script.Parent.Parent
local PlayerHead = Player.Head
local Goggles = Player:FindFirstChild("Goggles1")

Tool.Activated:Connect(function()
	if Queso == true then
		Queso = false
		NVE.Enabled = true
	else
		NVE.Enabled = false
		Queso = true
	end
end)

PlayerHead:GetPropertyChangedSignal('LocalTransparencyModifier'):Connect(function()
	Goggles.Transparency = PlayerHead.LocalTransparencyModifier 
end)

1 Like

How? Why so much exaggeration to detect if the player is in first person or not?

1 Like