CameraSubject not changing

Hey folks, I’m trying to change the camera’s subject to a different part, but it doesn’t seem to be working. I read some other topics with the same issue as mine and changed up some things in my script, still no luck. Here is my script:

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer

local function resetCameraSubject()
	if workspace.CurrentCamera and localPlayer then
		local Katamari = localPlayer:FindFirstChildOfClass("Model")
		if Katamari then
			workspace.CurrentCamera.CameraSubject = Katamari:FindFirstChild("Katamari")
		end
	end
end

resetCameraSubject()

To me everything here seems like it should work, unless I got the type of script it should be or the service its in incorrect (normal script in serverscriptservice). Could anybody please point out what I’m doing wrong?

2 Likes

I’ve the same problem Bro I hope somebody answer :frowning:

Why would you try to change the camera subject to something within the player, and not something within workspace? I believe to change the camerasubject, the new object has to be inside workspace. Also, LocalPlayer does not work in Server scripts, and works only inside of local scripts. Changing the CameraSubject will also only have an effect in local scripts as the player views the object Locally, not based on server.

1 Like

LocalPlayer isn’t accessible from the server, and returns nil, so

will always fail and the code will never run. Even if it did run, there wouldn’t be any visible difference because you should use LocalScripts to change the CameraSubject.

Thankyou, I did not know this. Just one last question though; should I put the localscript somewhere else, or keep it in serverscriptservice?

Local scripts wont run in serverscriptservice I think

LocalScripts will not run in ServerScriptService. They only run in:

  • The player’s Backpack

  • The player’s PlayerGui

  • The player’s character

  • The player

1 Like

Sorry to keep bothering you, but I made some changes to the script after putting it into startercharacterscripts, and it still doesn’t seem to be working.

local localPlayer = script.Parent

local function resetCameraSubject()
	if workspace.CurrentCamera and localPlayer then
		local Katamari = localPlayer.Katamari
		if Katamari then
			workspace.CurrentCamera.CameraSubject = Katamari:FindFirstChild("Katamari")
		end
	end
end

resetCameraSubject()

I remember an earlier reply mentioned that you could only change the camerasubject to something within the workspace and not within the player. I’m not sure if this is true, but could that be the problem?

Is there any error on output?
()

1 Like

:man_facepalming: That would be the problem, thankyou everyone for all your help, it works now.