Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

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.

0

can you help me with it?

2 answers

✓ Accepted answer

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

5 comments

0

Ty so much

0

how do it is work?

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.

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.

0

Line 14 enables scrolling when you are almost back to first person. Hope I helped!

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)

1 comment

0

:connect should be :Connect in line 5, and when changed to classic, will only allow scrolling, not automatically put them to third person.

This discussion is preserved as it was. New answers, comments, and votes are closed.