Problem with CameraSubject

local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local CameraSubject = Camera.CameraSubject
local Item = workspace.CameraItem -- Item is a Part

game.Players.PlayerAdded:Connect(function()
	Player.CharacterAdded:Connect(function()
	CameraSubject = Item
	end)
end)

Why is the CameraSubject not the CameraItem, instead it’s the LocalPLayer’s Character? Btw it’s a StarterPlayerScript

1 Like

The CameraSubject property determines the object that the camera is following or focusing on. In your code, you are setting the CameraSubject to the Item part, but it is not taking effect because the CameraSubject needs to be set after the character is added to the game.

To fix this, you can move the line CameraSubject = Item inside the Player.CharacterAdded event handler. Here’s an updated version of your code:

local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Item = workspace.CameraItem -- Item is a Part

Player.CharacterAdded:Connect(function(character)
	Camera.CameraSubject = Item
end)

By setting the CameraSubject inside the Player.CharacterAdded event handler, it ensures that the CameraSubject is set to the Item part after the player’s character is added to the game.

1 Like

Correct solution but incorrect reasoning for it.

His original code doesn’t work because he’s setting the variable to Item and not the actual property of the CurrentCamera.

local CameraSubject = Camera.CameraSubject just creates a variable which is the CameraSubject but changing this variable won’t change Camera.CameraSubject because it just doesn’t work like that.

One way to better explain this is an analogy:
For example, if you have a jar of marbles but want to see how many marbles there are, you’d create a variable marblesInJar. If you were to change this variable, the variable would change but the actual number of marbles in the jar won’t.