I'm not very experienced but i wanted to try to get a camera script to make the camera to be a kind of sidescrolling camera, so I looked at a tutorial from the developer hub and copied the scripts, but i realized that the script for some reason only made it so that the camera could follow you when you move right and it also slowly moved behind you when you kept moving, so I decided to change some things. I tried to just set it so that the camera's x position was the same as the player's, but it doesn't seem to be working. How do I fix it?
local cameraHeight = 12 local cameraZOffset = 20 local cameraSpeed = .25 local camera = game.Workspace.CurrentCamera local player = game.Players.LocalPlayer local RunService = game:GetService('RunService') wait(1) local function setupCamera() camera.CFrame = CFrame.new(Vector3.new(player.Character.HumanoidRootPart.Position.X,cameraHeight,cameraZOffset),Vector3.new(0,cameraHeight,0)) end setupCamera() player.CharacterAdded:Connect(setupCamera) RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value)
You forgot the third argument of BindToRenderStep
on line 17.
Also, I changed the position of some things and added some more variables to make it look nicer.
I would suggest removing the wait, if you don't have any sort of purpose for it.
local RunService = game:GetService("RunService") local cameraHeight = 12 local cameraZOffset = 20 local cameraSpeed = .25 local player = game.Players.LocalPlayer wait(1) -- consider removing local function setupCamera() local camera = workspace.CurrentCamera local character = player.Character or player.CharacterAdded:Wait() local root = character:WaitForChild("HumanoidRootPart") -- ^ extra variables because the other code looked sorta messy camera.CFrame = CFrame.new(Vector3.new(root.Position.X, cameraHeight, cameraZOffset), Vector3.new(0, cameraHeight, 0)) end RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, setupCamera) -- you bind anything to render step