How do I change the player's camera CFrame to be at a part's CFrame?

I was trying to change the player’s camera CFrame to be at a part’s CFrame here’s the code that I used:

local CameraStart = workspace:WaitForChild("CameraStart")
local camera = workspace.CurrentCamera

camera:GetPropertyChangedSignal("CameraType"):Wait()
camera.CameraType = Enum.CameraType.Fixed
camera.CFrame = CameraStart.CFrame

When I tried using that code I noticed that the player’s camera is nowhere near the part and changing the CameraType to “Scriptable” will make the player’s camera appear in a different location and it’s still nowhere near the part.

The image below will show where the player camera’s location and part’s location are at when the CameraType is set to “Scriptable”:

The player camera’s CFrame also have the same CFrame as the part but the player camera is nowhere near the part so that is weird, does anyone know why this is happening and how to fix this?

Maybe try setting the camerasubject to the part and set to scriptable
script should look like

local CameraStart = workspace:WaitForChild("CameraStart")
local camera = workspace.CurrentCamera

camera:GetPropertyChangedSignal("CameraType"):Wait()
camera.CameraSubject = CameraStart
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CameraStart.CFrame

and try doing it in a localscript so it only effects the localplayer

1 Like

Changing the CameraSubject to the part does nothing so that’s not the problem, it was also already a local script.

1 Like

check the output to see if you find any errors

The script doesn’t error, the issue is that the player camera’s is supposed to be at the part but it’s not, the player camera’s CFrame also have the same CFrame as the part so I don’t know why it’s nowhere near the part.

local CameraStart = workspace:WaitForChild("CameraStart")
local camera = workspace.CurrentCamera


Connection = camera:GetPropertyChangedSignal("CameraType"):Connect(function()
	if camera.CameraType ~= Enum.CameraType.Scriptable then
		camera.CameraType = Enum.CameraType.Scriptable
	end
end)


camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CameraStart.CFrame

-- Remove Connection When Done -> 'Connection:Disconnect'
7 Likes

That code works, you fixed the issue but could you explain why my code wouldn’t work?

I was changing the player camera’s CFrame like you did but it still wouldn’t work for me but your code worked somehow…

Not sure exactly, im guessing the camera gets changed to custom from scriptable when the character loads, so to make it work you force it to stay on scriptable with the changed signal

What you said won’t do anything though

Glad you got that solved!
I just want to clarify to anyone that has the same issue that it is 99% an overlapping issue with the default player scripts, or the PlayerModuleCameraModule to be more specific. In a normal environment, upon joining, any LocalScripts will run before the Character even exists, meaning your code will change the CameraType, but upon spawning the Character, the default CameraModule kicks in and reverts it back.

It’s quite common for people to create an empty, disabled LocalScript named exactly like the default ones inside the StarterPlayerScripts if you’re planning on coding your own systems from scratch. Otherwise, a workaround will be having to delay enough where the code runs after the character loads in (ie; a gui button) or “brute forcing” it, like what @kylerzong did.

6 Likes