Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I detect if a player goes into first person?

Asked by 4 years ago
Edited 4 years ago

I want to print "Player is now in first person." every time the player goes into first person. How would I do this? I have checked developer.roblox.com, but it doesn't seem to have an event for going into first person.

Edit: After it detects that the player is in first person, how would I detect when the player leaves first person?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You have to use magnitude which is the distance between parts. Make sure it's a LocalScript.

local function isFirstPerson()
    local camera = workspace.CurrentCamera
    local character = game:GetService("Players").LocalPlayer.Character or  game:GetService("Players").LocalPlayer.CharacterAdded
    if (character.Head.CFrame.p - camera.CFrame.p).magnitude < 1 then
        return true
    else
        return false
    end
end

while wait() do
    local isFirstPerson = isFirstPerson()

    if isFirstPerson == true then
        print("Player is now in first person.")
    end
end

The isFirstPerson() function returns true if the player is in first person.

0
How do I detect if the player exist first person? KyofuOmo 25 — 4y
0
Would I use an elseif? KyofuOmo 25 — 4y
0
Just use "else". youtubemasterWOW 2741 — 4y
0
ok, got it. thanks! KyofuOmo 25 — 4y
Ad

Answer this question