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)
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)
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.