So I am making a script where people can click F and change between two camera modes, First and Third. The problem is that when the person switches back from First to Third, they have to zoom out manually to be fully in third person. Anyone know how I can fix it so that it automatically zooms the camera out into fully third person mode?
Code:
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local tps = true
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.F then
if tps then
plr.CameraMode = Enum.CameraMode.LockFirstPerson
tps = false
else
plr.CameraMode = Enum.CameraMode.Classic
tps = true
end
end
end
end
end)
Note: This is my first ever post so please do understand if I made some mistakes, Thanks!
First of all, please organize your code. It’s basically un-readable in this state. Second, there are quite a few tutorials for this on the dev forum. Please do research before coming here to post. This should be your last resort.
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local rbxCamera = game.Workspace.CurrentCamera
local length = 5
local tps = true
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.F then
if tps then
plr.CameraMode = Enum.CameraMode.LockFirstPerson
tps = false
else
plr.CameraMode = Enum.CameraMode.Classic
rbxCamera.CFrame = rbxCamera.CFrame * CFrame.new(0,0,-length)
tps = true
end
end
end
end)
hey, this isn’t a solution to your problem but quick tip:
you can do tps = not tps regardless if it’s true or false, it will always change it to the opposite boolean. for example, you can change tps = false with tps = not tps to tps = true and same happens vice versa.
No, im trying to make it so that the camera automatically gets zoomed out of first person mode when a player switches to third person instead of having to scroll/zoom out manually.
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local rbxCamera = game.Workspace.CurrentCamera
local length = 5
local tps = true
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.F then
if tps then
plr.CameraMode = Enum.CameraMode.LockFirstPerson
tps = false
else
plr.CameraMode = Enum.CameraMode.Scriptable
rbxCamera.CFrame = rbxCamera.CFrame * CFrame.new(0,0,-length)
plr.CameraMode = Enum.CameraMode.Classic
tps = true
end
end
end
end)
I’ve proposed to you a solution. FOV has nothing to do with anything related to this post. Its simply how much of the world you can view from your camera
I have found a solution to my problem. What you can do is change the CameraMinZoomDistance to your desire distance and quickly change it back to the default(0.5).
local Players = game:GetService(“Players”)
local plr = Players.LocalPlayer
local UIS = game:GetService(“UserInputService”)
local tps = true
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.F then
if tps then
plr.CameraMode = Enum.CameraMode.LockFirstPerson
tps = false
else
plr.CameraMode = Enum.CameraMode.Classic
tps = true
end
end
end
end
end)