I’m trying to make a script that fixes the Player’s camera onto a certain object as soon as they join, as demonstrated in the image below.
I’ve seemingly tried everything imaginable at this point. I’ve tried every option in “Camera”, made scripts that would do it for me, nothing’s working.
What am I missing?
1 Like
If you want the camera to be “stuck” on a position, use camera.CFrame, will move and orient the camera.
If you want the camera to follow a part, use camera.CameraSubject
1 Like
shabman
(shab)
December 31, 2020, 5:28pm
3
First, change the camera type to scriptable to allow the camera to be moved. Then change the CFrame of the camera to move its position
Example:
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = TargetName.CFrame -- change to the target
2 Likes
This line doesn’t help, because the Camera switches automatically back to “Custom” when the Player loads in. How do I make sure that doesn’t happen?
1 Like
Apxoza
(Apxoza)
December 31, 2020, 5:54pm
6
Use a repeat loop:
repeat
wait() camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable
1 Like
Did exactly what you said, the Camera still remains as “Custom” even after long periods of time.
Just to be clear, is this script supposed to be a LocalScript?
1 Like
shabman
(shab)
December 31, 2020, 6:16pm
8
of course its supposed to be in a local script because you want to access the client’s camera.
3 Likes
Apxoza
(Apxoza)
December 31, 2020, 6:31pm
9
Make sure it’s not nil:
repeat wait() until workspace.CurrentCamera ~= nil
local camera = workspace.CurrentCamera
repeat wait() camera.CameraType = Enum.CameraType.Scriptable until camera.CameraType == Enum.CameraType.Scriptable
camera.CFrame = workspace.Test.CFrame
also yes, it needs to be in a LocalScript.
Try putting it in StarterPlayer > StarterPlayerScripts
4 Likes
This is what I get when I put the script in StarterPlayerScripts.
I receive no warnings when the script is in workspace, however the script doesn’t function regardless.
1 Like
I don’t think you’re supposed to include the repeat wait() in line 3, the first line in Line #1 is fine enough
camera.CameraType = Enum.CameraType.Scriptable
Apxoza
(Apxoza)
December 31, 2020, 6:49pm
12
That’s your problem. LocalScript’s don’t run in Workspace.
Can’t reproduce that error. Copy and pasted into my local script and I didn’t get that.
Apologies, I had the script completely wrong.
It’s working fine now. Thanks.