How to detect if a player is in first person?

I want the connection to stop when I am not in first person, but when I am in first person, the model shows (connection is enabled or connected)

I changed a bit so feel free to ask me if any changes aren’t obvious as to the reasons. I also was unable to test, and though I don’t think there are errors… There always are errors.

--Services
local RunService = game:GetService("RunService")
local ReplicatedFirst = game.ReplicatedFirst

local VIEW_M = ReplicatedFirst.Sword

--Player Junk
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local CurrentCamera = workspace.CurrentCamera



local Tool = script.Parent
local RUNNING, VIEW_M_CLONE

Tool.Equipped:Connect(function()
	if player.CameraMinZoomDistance <= 0.5 then
		VIEW_M_CLONE = VIEW_M:Clone()
		
		RUNNING = RunService.RenderStepped:Connect(function() -- Create a function that I can easily disconnect
			local distance = (CurrentCamera.CFrame.p - CurrentCamera.Focus.p).magnitude 
			local isFirstPerson = distance <= 0.75
			
			if isFirstPerson and not VIEW_M_CLONE.Parent then
				VIEW_M_CLONE.Parent = game.Workspace
			elseif not isFirstPerson and VIEW_M_CLONE.Parent then
				VIEW_M_CLONE.Parent = nil
			end
			
			
			if VIEW_M_CLONE.Parent then -- If the viewmodel is actually there, do stuff
				--print("VIEW_M_CLONE CHECK COMPLETE")
				VIEW_M_CLONE.Parent = workspace
				VIEW_M_CLONE:SetPrimaryPartCFrame(CurrentCamera.CFrame * CFrame.new(0,0,0))
			end
		end)
	end
end)

Tool.Unequipped:Connect(function()
	if RUNNING then
		RUNNING:Disconnect()
	end
	
	if VIEW_M_CLONE then
		VIEW_M_CLONE:Destroy()
		VIEW_M_CLONE = nil
	end
end)
3 Likes

Worked! Thank you :^)

(random words to fill up space)

2 Likes