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:
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!
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
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
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?
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
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 :
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)
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
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