How to setup camera on join?

I am trying to set the camera of players joining to a scenery I made until they hit “Play,” but I am having issues setting that up.
Shouldn’t this setup the camera? (It’s a LocalScript inside the StarterGui.MainMenu)

local Cam = workspace.CurrentCamera
local bCam = workspace.Background.Camera.CamPart

Cam.CameraType = Enum.CameraType.Scriptable
Cam.FieldOfView = 70
Cam.CFrame = bCam.CFrame

Try setting the CFrame of the camera to the CFrame of an invisible, anchored part. This is how I usually do it.

local cameraPart = workspace:WaitForChild("CameraPart")
local camera = workspace.Camera

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cameraPart.CFrame

That’s exactly what I am doing in the script, no? But it’s still not working. Also, are you sure it’s: workspace.camera not workspace.CurrentCamera? Or are they the same?

–Edit: Maybe it’s something wrong with how I set-up my Camera?
image
Camera Properties:
image

You could go either way, workspace.CurrentCamera just references the workspace.Camera

1 Like

Maybe try setting the CFrame every frame using RunService:

local RunService = game:GetService("RunService")

local camera = workspace.CurrentCamera
local cameraPart = workspace.Background.Camera.CamPart

camera.CameraType = Enum.CameraType.Scriptable

RunService.RenderStepped:Connect(function()
    camera.CFrame = cameraPart.CFrame
end)
1 Like

I don’t think the issue is that deep, it must be on the way I set-uped my camera, do you think you see any issue with it? I changed the Camera parent to workspace and put the camera block which is just a square part also in workspace.

You only need one camera instance (default camera) and one BasePart in the workspace for my code to work. If it’s a LocalScript inside of StarterGui, it should work.

Still cannot get it to work, does the BasePart need to have a Camera instance linked to it or how does this work? When you say

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cameraPart.CFrame

It’s setting the camera to which face of the camerapart?

The camera’s CFrame will be set to the part’s position, looking in the direction that the part’s front face is facing.

1 Like

See that makes sense, so why is it not applying that when I am doing:

local Cam = workspace.Camera
local bCam = workspace:WaitForChild("CamPart")

Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = bCam.CFrame

I think I know the issue, when I did what you told me about using RenderStepped, the output gives me the error of " Cframe is not a valid member of Part “Workspace.CamPart”"

And that doesn’t make much sense to me

Oh god, the issue is the capitalization…

The only other thing I can think of is that maybe it is working, but it’s reverting back to it’s original CFrame right after. Try the RunService method I mentioned earlier to see if that makes a difference:

local RunService = game:GetService("RunService")

local Cam = workspace.Camera
local bCam = workspace:WaitForChild("CamPart")

RunService.RenderStepped:Connect(function()
    Cam.CameraType = Enum.CameraType.Scriptable
    Cam.CFrame = bCam.CFrame
end)

Maybe you did “Cframe” instead of “CFrame” ?

While that works, the scenary is now much more morphed and looks very ugly.
Original:


Using RunService:

Could the problem be that this scenery’s position is: (-549.873, 9811.138, -2851.916)?

If the player is very, very far away the scene will not render fully.

Yeah, that’s quite a distance :sweat_smile:

Edit: Unless your character spawns in that general location as well.

1 Like

Ok, I dragged the spawn point to there and now it looks beatiful, thanks for the biiiig help. Just one last question, if I make it so when the player hits Play, the LocalScript destroys the GUI this destroying the script with it, would the camera go back to its original place and follow the player like usually?

Probably not, you would want to first set the CameraType back to “Custom”. The RenderStepped event should stop if the script is destroyed, but if not you’ll want to :Disconnect() it.

To disconnect it, make sure your RenderStepped event is stored in a variable:

local connection = RunService.RenderStepped:Connect(function()

end)
connection:Disconnect()
1 Like

Brilliant, I’ll make sure to use this if what I sugguested doesn’t work. Thanks again for the help!

1 Like

I would also take into consideration the player returning to the menu. I would keep the RenderStepped running, but have a conditional inside to check if the player is in the menu.

1 Like

That’s true, but it seems that, in this case, he is destroying the script once he presses play: