You’re going to want to set the CameraType to “Scriptable”.
You need to determine which direction your levels are being built on. If the player constantly moves towards a higher X position, then you can base your camera’s position off of that. I’ll try to get an example put together for you.
For this solution, I’m using an invisible, anchored part to position the camera.
You can create a simple part and anchor it in the world. Name the newly created part to anything that is easy to reference. For example, “CameraView”. Set the part’s Transparency to 1, making it invisible.
Next, we want to position the Camera on the part, but also lock it’s position with the player’s Y position. In code, we’ll set the part’s position before setting the camera’s position.
local Player = game.Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Camera = workspace.CurrentCamera;
repeat -- This was a weird hack, but you just need to set the CameraType to Scriptable.
wait();
Camera.CameraType = Enum.CameraType.Scriptable;
until Camera.CameraType == Enum.CameraType.Scriptable;
game["Run Service"].Stepped:Connect(function(t, deltatime)
workspace.CameraView.CFrame = CFrame.new(workspace.CameraView.CFrame.X, Character.HumanoidRootPart.Position.Y, Character.HumanoidRootPart.Position.Z); -- Set the parts Y and Z to the player's position.
Camera.CFrame = CFrame.new(workspace.CameraView.CFrame.Position, Character.HumanoidRootPart.CFrame.Position); -- Set the camera's CFrame to the part's position, and to look at the player's HumanoidRootPart position.
end)
The code above positions the part on its X and Z position, Which keeps it from moving back and forth or diagonally. However, we set the Y position of the part to the player’s Y position. Which allows it to go up and down.
Then, the camera’s CFrame is set to the part’s position, and to look at the player’s HumanoidRootPart position. Giving us a 2D camera.
There are many different ways to achieve a 2D camera without a part, but this is a good starting point. It can also help you learn the 2D camera concept visually.