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

1st person to 3rd person?

Asked by
Sitch 0
8 years ago

Hi! So I know how to make it that a player can zoom from 1st person to 3rd person but my question is how would I make it so if the player hits a letter like "t' they can switch views?

0
So you want the code for pressing the button? viralmoose 65 — 8y
2
is Scripting Helpers = sCRIPTING mAKERS? davness 376 — 8y
0
I sure hope not... viralmoose 65 — 8y
0
No I know the script but I want to know how to switch views when I hit a button Sitch 0 — 8y
0
Please Accept my answer if it helps! It also gives you reputation so you don't get suspended. EzraNehemiah_TF2 3552 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

There is a feature called "LockFirstPerson". You could also use UserInputService to see if they pressed a key


UserInputService

UserInputService acts like KeyDown but it isn't actually deprecated and it takes ANY type of input(Clicking, Chatting, Etc).

local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(input, chat)
    if input.KeyCode == Enum.KeyCode.T and not chat then --If they press T and is not chatting/typing into a textbox then...
        print("Pressed T!")
    end
end)

CameraMode

A players has something called CameraMode. There is Classic(Third Person) and LockFirstPerson(1st person obviously.)

game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
wait(3)
game:GetService("Players").LocalPlayer.CameraMode = Enum.CameraMode.Classic


Final Product

--LocalScript
local uis = game:GetService("UserInputService")
local plyr = game:GetService("Players").LocalPlayer

uis.InputBegan:connect(function(input, chat)
    if input.KeyCode == Enum.KeyCode.T and not chat then
        if plyr.CameraMode == Enum.CameraMode.Classic then
            plyr.CameraMode = Enum.CameraMode.LockFirstPerson
        else
            plyr.CameraMode = Enum.CameraMode.Classic
        end
    end
end)



Hope it helps!

0
Thank you very much! This was helpful! Sitch 0 — 8y
Ad

Answer this question