How do i make a player go first person?

I want to make a player go first person then out of first person smoothly, where when it switches to first person the player is just in first person and it doesn’t zoom in.

i want to make a cut scene but the player is in first person and they switch from first to third. but when switching back to first it earthier doesn’t work or it slowly zooms to first person.

the game is always will be in first person.

here is the script:

-- __ -- __ -- Important -- __ -- __ --

local humanoid = script.Parent:FindFirstChild("Humanoid")
local Player = game:GetService("Players").LocalPlayer
local Rep = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Stop = false

-- __ -- __ -- Animation Sets -- __ -- __ --


local LeverOn = script:WaitForChild("LeverOn")
local LeverOnAnimation = humanoid.Animator:LoadAnimation(LeverOn)

Rep.AnimationTriggers.LeverOn.OnClientEvent:Connect(function(Object)

	humanoid.WalkSpeed = 0
	print(humanoid.WalkSpeed)
	humanoid.Parent.HumanoidRootPart.CFrame = CFrame.new(Object.Value.Position)
	humanoid.Parent.HumanoidRootPart.CFrame *= CFrame.Angles(math.rad(Object.Value.Orientation.X), math.rad(Object.Value.Orientation.Y), math.rad(Object.Value.Orientation.Z))
	humanoid.Parent.HumanoidRootPart.Anchored = true

	delay(1.917, function()
		Stop = true
	end)

	LeverOnAnimation:Play()
	
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

	local function onLeverPullAnimation()

		local R = RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value + 3, function()
			workspace.CurrentCamera.CFrame = humanoid.Parent.Head.CFrame

			if Stop == true then

				humanoid.Parent.HumanoidRootPart.Anchored = false
				humanoid.WalkSpeed = 16

				Stop = false
				
				workspace.CurrentCamera.CameraType = Enum.CameraType.Custom

				RunService:UnbindFromRenderStep("CameraUpdate")
			end
		end)
	end

	onLeverPullAnimation()

end)




local LeverOff = script:WaitForChild("LeverOff")
local LeverOffAnimation = humanoid.Animator:LoadAnimation(LeverOff)

Rep.AnimationTriggers.LeverOff.OnClientEvent:Connect(function(Object)
	
	humanoid.WalkSpeed = 0
	print(humanoid.WalkSpeed)
	humanoid.Parent.HumanoidRootPart.CFrame = CFrame.new(Object.Value.Position)
	humanoid.Parent.HumanoidRootPart.CFrame *= CFrame.Angles(math.rad(Object.Value.Orientation.X), math.rad(Object.Value.Orientation.Y), math.rad(Object.Value.Orientation.Z))
	humanoid.Parent.HumanoidRootPart.Anchored = true

	delay(1.917, function()
		Stop = true
	end)

	LeverOffAnimation:Play()

	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

	local function onLeverPullAnimation()

		local R = RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value + 3, function()
			workspace.CurrentCamera.CFrame = humanoid.Parent.Head.CFrame

			if Stop == true then
				
				humanoid.Parent.HumanoidRootPart.Anchored = false
				humanoid.WalkSpeed = 16

				Stop = false
				
				workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
				
				RunService:UnbindFromRenderStep("CameraUpdate")
			end
		end)
	end

	onLeverPullAnimation()

end)

CFrame are a bit complicated,have you tried to force FPS?
Or try to temporarily enable TPS on a target cutscene so when it ends the script will disable it soon after

Try this:

local humanoid = script.Parent:FindFirstChild("Humanoid")
local Player = game:GetService("Players").LocalPlayer
local Rep = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Stop = false

local LeverOn = script:WaitForChild("LeverOn")
local LeverOnAnimation = humanoid.Animator:LoadAnimation(LeverOn)

Rep.AnimationTriggers.LeverOn.OnClientEvent:Connect(function(Object)
	humanoid.WalkSpeed = 0
	humanoid.Parent.HumanoidRootPart.CFrame = CFrame.new(Object.Value.Position)
	humanoid.Parent.HumanoidRootPart.CFrame *= CFrame.Angles(
		math.rad(Object.Value.Orientation.X),
		math.rad(Object.Value.Orientation.Y),
		math.rad(Object.Value.Orientation.Z)
	)
	humanoid.Parent.HumanoidRootPart.Anchored = true

	delay(1.917, function()
		Stop = true
	end)

	LeverOnAnimation:Play()

	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

	local function onCameraUpdate()
		workspace.CurrentCamera.CFrame = humanoid.Parent.Head.CFrame

		if Stop then
			humanoid.Parent.HumanoidRootPart.Anchored = false
			humanoid.WalkSpeed = 16
			Stop = false
			workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
			RunService:UnbindFromRenderStep("CameraUpdate")
		end
	end

	RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value + 3, onCameraUpdate)
end)

local LeverOff = script:WaitForChild("LeverOff")
local LeverOffAnimation = humanoid.Animator:LoadAnimation(LeverOff)

Rep.AnimationTriggers.LeverOff.OnClientEvent:Connect(function(Object)
	humanoid.WalkSpeed = 0
	humanoid.Parent.HumanoidRootPart.CFrame = CFrame.new(Object.Value.Position)
	humanoid.Parent.HumanoidRootPart.CFrame *= CFrame.Angles(
		math.rad(Object.Value.Orientation.X),
		math.rad(Object.Value.Orientation.Y),
		math.rad(Object.Value.Orientation.Z)
	)
	humanoid.Parent.HumanoidRootPart.Anchored = true

	delay(1.917, function()
		Stop = true
	end)

	LeverOffAnimation:Play()

	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

	local function onCameraUpdate()
		workspace.CurrentCamera.CFrame = humanoid.Parent.Head.CFrame

		if Stop then
			humanoid.Parent.HumanoidRootPart.Anchored = false
			humanoid.WalkSpeed = 16
			Stop = false
			workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
			RunService:UnbindFromRenderStep("CameraUpdate")
		end
	end

	RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value + 3, onCameraUpdate)
end)

So basically what i did is combined the onLeverPullAnimation function into the onCameraUpdate function for better code organization, and simplified the if Stop == true checks to just if Stop

2 Likes

I am pretty sure you can lerp the camera’s max zoom distance and minimum zoom distance to make it the same and so that it is moving out.

There is a CameraMode in StarterPlayer, which allows the player to go first person.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.