How do I detect when someone enters first person/shift lock?

My goal is to make a corner clip fix script (since corner clipping was patched as of december 10th, 2021) but I don’t know how to detect when someone enters first person/shift lock to even start on this.

Does anyone know how to detect when a player enters first person/shift lock?

EDIT: I found out how to detect shift lock, now I need to find out how to detect first person.

My shift lock detection script:

if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
       -- code
end
1 Like

there are a few different methods to go about this

  1. Checking the humanoid camera offset:
    simply just use an if statement on the humanoid and check to see if the camera is offsetted, by default i think the offset is Vector3.new(3, 0.2, 0).
    so just do if hum.CameraOffset == Vector3.new(3, 0.2, 0) then blah blah blah blah end

  2. Actually fiddle with the shift lock code, and use a bool value and toggle it whenever enabled/disabled

  3. checking if the mouse is locked or not.
    i would highly advise against this if you have zooming into first person enabled.

1 Like

You can use UserInputService and detect when a player enters ShiftLock by listening for MouseBehavior’s LockCenter

Example:

if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
        lockCenter = true
end
3 Likes

Nice.

Got a method for shift lock, now need one for first person.

https://developer.roblox.com/en-us/api-reference/property/BasePart/LocalTransparencyModifier

I found this unique property which supposedly gives you the Transparency of your Character’s BaseParts from the local side

As when you zoom into first person, your Character’s BaseParts turn transparent although I am unsure if you can detect it’s changed property signal you could use a RenderStepped event to check if the Transparency is equal to 1

local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")

 --If this first one doesn't work, stick with the RenderStepped event
Head:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
    if Head.LocalTransparencyModifier == 1 then
        -- Rando Code Here
    end
end)

--RunService.RenderStepped:Connect(function()
    --if Head.LocalTransparencyModifier == 1 then
        -- Rando Code Here
    --end
--end)
3 Likes

Try this:

if (character.Head.CFrame.p - camera.CFrame.p).magnitude < 1 then
  return true
 else	        
   return false
end

Returns true if the plr is in first person.