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?
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)
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.
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)
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)
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.