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 * CFrame.new(0, 0, 0.05)
Camera.CoordinateFrame = CFrame.new(Focus.p)
player.Character.Humanoid.Changed:Connect(function()
if (player.Character.Humanoid.Sit == false) then
player.Character.Parent = game.Workspace
script.Parent = nil
end
end)
end
if true then
Cam()
end
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.
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.