My First Person script broke

Greetings! I have a first person script that was recently reported to stop working, and now I cannot figure out how to fix it.

If you can help, please let me know.

Thanks in advance!

local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local Player = game:GetService("Players").LocalPlayer
local UI = Player.PlayerGui
if not Player.Character then
	Player.CharacterAdded:Wait()
end

local Character = Player.Character

-- Custom Variables
local Debounce = false

-- Custom Functions
script.Parent.MouseButton1Click:Connect(function()
	local Head = Character.Head
	if Head then
		Debounce = not Debounce
		if Debounce == true then
			script.Parent.TextLabel.Text = "Third Person"
			Camera.CameraType = Enum.CameraType.Scriptable
			repeat
				Camera.CFrame = Head.CFrame * CFrame.new(0, 0, -0.5)
				RunService.RenderStepped:Wait()
			until Debounce == false

			Camera.CameraType = Enum.CameraType.Custom
		else
			script.Parent.TextLabel.Text = "First Person"
		end
	end
end)

Try this, don’t know how to do debounces but I’m sure you’ll find a way to implement it. :smiley:

That script doesn’t work. Also, you got rid of RunService which is needed for the First Person script.

Please explain what do you expect to happen versus what actually happens in game. And any errors that occur in the logs

This is close! and we don’t need a de-bounce as we can reuse the camera type

script.Parent.MouseButton1Click:Connect(function()
    -- check if the camera is first person, replaces our de-bounce
    local wasFirstPerson = Player.CameraMode == Enum.CameraMode.LockFirstPerson

    -- setting text based on if the player was in first person
    script.Parent.TextLabel.Text = if wasFirstPerson then "Third Person" else "First Person" 

    -- if we're in first person we switch to classic, otherwise we switch to first person
    -- when this runs wasFirstPerson will be swapped!
    Player.CameraMode = if wasFirstPerson then Enum.CameraMode.Classic else Enum.CameraMode.LockFirstPerson
end)

It cannot find the head.

If you go into StartPlayer and scroll down to camera, you can find CameraMode and make it LockFirstPerson.
image
image

1 Like

There is only one downside to this approach:

My mouse is locked in the center of the screen. Can’t exit first person mode.

Same with the reply made by @gertkeno

Alright. Came up with a solution:

script.Parent.MouseButton1Click:Connect(function()
	if Player.CameraMode == Enum.CameraMode.Classic then
		Player.CameraMode = Enum.CameraMode.LockFirstPerson
	else
		Player.CameraMode = Enum.CameraMode.Classic
	end
end)

And I made the button’s .Modal property true, which unlocks first person camera movement.

2 Likes