Script skips part of if statement

I made this script where a player clicks on a TextButton and the camera focuses on a part called FrontCam. However, when in testing, there are no errors, but the script skips over the first part of the if statement and goes to the second (see screenshot). I have tried changing the CameraType, but it did not work. Please help!

local camera = game.Workspace.CurrentCamera
local focusPart = game.Workspace.Loco.FrontCam
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if camera.CameraType == "Scriptable" and player.Character.Humanoid then
		camera.CameraType = "Track"
		camera.Focus = focusPart.CFrame
		print("Focused on Part")
	else
		camera.CameraType = "Custom"
		camera.CameraSubject = player.Character.Humanoid
		print("Focused on Player")
	end
end)

Screenshot 2023-07-12 220849

1 Like

I would assume it’s because the condition of the cameraType being scriptable isn’t true, is why it skips over the first condition. I would first make sure that you are setting the camera type to “Scriptable” before the player would select the textbutton. You can also add a print statement before the if statement to debug it, like “print(camera.CameraType)” to make sure that the CameraType is scriptable. If all these conditions meet, then it’s the player.Character.Humanoid condition that is causing the issue.

1 Like
camera.CameraType == "Scriptable"

Should be

camera.CameraType == Enum.CameraType.Scriptable

There are also the parts where you do just “Track” and just “Custom” instead of Enum.CameraType.Track and Enum.CameraType.Custom.

Replace
if camera.CameraType == Enum.CameraType.Scriptable and player.Character:WaitForChild("Humanoid ") then