Player is nil

K don’t know why it gives me this error:
Workspace.Security Cameras.Head.Camera:12: attempt to index local ‘player’ (a nil value)

function Cam(player)
	local Camera = game.Workspace.CurrentCamera
	local Record = Camera.Focus
	local Subject = game.Workspace.CameraType1

	Camera.CameraSubject = Subject
	Camera.CameraType = ("Attach")

	local Focus = Camera.Focus *, 0, 0.05)
	Camera.CoordinateFrame =

		if (player.Character.Humanoid.Sit == false) then
            	 player.Character.Parent = game.Workspace
			script.Parent = nil

if true then



The “if true” statement at the bottom of your code serves no purpose, since “true” is always true, and that code will always run.

When you’re firing the Cam() function at the bottom of your code, you need to specify what “player” is.

Also, you should always have Camera.CameraType be equal to the Enum, and not the string.

The “player.Character.Parent = game.Workspace” seems useless, since the character should always be parented to workspace.

Your script should be a LocalScript, and should be parented either to StarterPack, StarterGui, StarterPlayerScripts, or StarterCharacterScripts. The camera can only be accessed via LocalScript.


that is an anonymous function, below you should fire the function and explain as to what “player” is

it should be

if true then
  Cam(your way of defining the "player")

EDIT: my bad, it can’t be a local script since it’s in the workspace

Adding onto what @brokenVectors and @MarkiPr0 said, the if true statement servers no purpose, you don’t need to do that to call a function. Also, when calling the function you need to send the player since it’s an argument in it; Cam(Player). Assuming it’s a local script, you can do Cam(game.Players.LocalPlayer), otherwise you need another way to get the player as this method of getting the player cannot be done outside of a local script. :+1:

The error is gone but the script doesnt work.

Hope I helped!(30 charssssssss)