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

How do when i press a key it makes me go First Person Mode? [FIXED]

Asked by 4 years ago
Edited 4 years ago

How do when i press a key it makes me go First Person Mode? I will normally ask here for help in this website because i'm a new developer and i need help to start good with my game.

So i already have this scripts that i know in Starter Player Scripts, how do i continue?

local m = game.Players.LocalPlayer:GetMouse()
db = true
m.KeyDown:connect(function(k)
    k = k:lower()
    if k == "V" then
        if db == true then
            --FP Camera script goes here.
        end
    end
end)

If you guys know, please help me.

0
Apply UserInputService KeyDown is deprecated. Not only that, you set the Key to lowercase, and are comparing it in upper. Set Player.CameraMode to LockFirstPerson. Ziffixture 6913 — 4y
0
can you help me with it? PencilPlaysRBLX 2 — 4y

2 answers

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

Hey Pencil, You are on the right track. Try using this in the same location (LocalScript in StarterPlayerScripts)

local x = 13 --How far they can zoom out
game.Players.LocalPlayer.CameraMaxZoomDistance = x
local m = game.Players.LocalPlayer:GetMouse()
m.KeyDown:Connect(function(k)
    k = k:lower()
    if k == "v" then
        if game.Players.LocalPlayer.CameraMode == Enum.CameraMode.Classic then
            print("First Person")
            game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
        else
            print("Third Person")
            game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
            game.Players.LocalPlayer.CameraMinZoomDistance = 10
            game.Players.LocalPlayer.CameraMinZoomDistance = 0.5
        end
    end
end)

If this works, please accept my answer. If you need an explanation on how this works, don't hesitate to reply to this message. Thanks, LennyPlayzYT

0
Ty so much PencilPlaysRBLX 2 — 4y
0
how do it is work? PencilPlaysRBLX 2 — 4y
0
Great! If it works, please accept my answer. Line 1 determines how far the player can zoom out, with Line 2 changing the Max Zoom Distance to "x". Line 3 is defining the mouse, while Line 4 detects when a key is down. The key will become lowercase, due to line 5. Line 6 has an if statement if the key pressed is "v". If it is, it will check if you are in first person or in third person. LennyPlayzYT 269 — 4y
0
If you are in third person currently, it will lock you into first person (Lines 7-9). If you are in locked first person, it will bring you to third person. (Lines 10-14). About lines 13 and 14, putting the MinZoomDistance to 10 makes it the regular distance when a player joins a game, so once "v" is pressed, it will AUTOMATICALLY bring you to third person. LennyPlayzYT 269 — 4y
0
Line 14 enables scrolling when you are almost back to first person. Hope I helped! LennyPlayzYT 269 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Here is the code for to toggle 1st person mode:

local p = game.Players.LocalPlayer
local m = p:GetMouse()
local db = true
local enabled = false
m.KeyDown:Connect(function(k)
    if k:lower() == "v" then
        if db == true then
            if enabled == true then
                enabled = false
                p.CameraMode = Enum.CameraMode.Classic
                db = false
                wait(1)
                db = true
            else
                enabled = true
                p.CameraMode = Enum.CameraMode.LockFirstPerson
                db = false
                wait(1)
                db = true
            end
        end
    end
end)
0
:connect should be :Connect in line 5, and when changed to classic, will only allow scrolling, not automatically put them to third person. LennyPlayzYT 269 — 4y

Answer this question