Detect if player is in first person

So I made a gun and I wanted to make an aim system. but I want the aim system to change the camera fov. But I want it to be able to only aim if the player is in the first person. How could I detect if the player is in the first person while holding the tool?

2 Likes
local player = game.Players.LocalPlayer


    player.CharacterAdded:Connect(function(char)
    	local head = char:WaitForChild("Head")
    	local tool = player:WaitForChild("Backpack").Tool
    	
    	if head.LocalTransparencyModifier > 0.6 and tool.Parent == char then
    		print("player is in first person")
    	end
    end)

try this, mess around with the value

1 Like

Im trying to make it for my tools not when the player joins

You should be checking if it’s equal to 1, this way it’s guaranteed that the player is actually in first person. As for OP, connect your tool with the equipped event and do the check.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild('Head')

local tool = script.Parent
tool.Equipped:Connect(function()
    if head.LocalTransparencyModifier == 1 then
    -- player is in 1st person
    else
    -- player is not in 1st person
    end
end)
5 Likes

It works, but how do I detect if it changes because I made it so it prints goodbye if the player is in 3rd person and prints hi in the first person. but when I equip the tool while in 3rd person it prints by. but if I zoom in whitout unequipping the tool it still doesn’t print Hi? How can I fix it?

You can use a loop to constantly check that, though there are probably better ways to do this. Actually, I think a better way to do is it use GetPropertyChangedSignal.

tool.Equipped:Connect(function()
	head:GetPropertyChangedSignal('LocalTransparencyModifier'):Connect(function()
		if head.LocalTransparencyModifier == 1 then
	    	-- player is in 1st person
		else
	     	-- player is not in 1st person
		end
	end)
end)
25 Likes