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?
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'
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
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 PlayerModule → CameraModule 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.