Help With Custom player camera Camera

Hi, I made a script where when you step on a part it moves a script into the players starter GUI. That script changes the angle of the player’s camera. The script works but you can move the camera away from that position. I was wounding how to make the camera stay on that angle?

Script

local offset = Vector3.new(0,0,30)
local fieldOfView = 70
local player = script.Parent.Parent
local camera = game.Workspace.CurrentCamera
local runService = game:GetService(“RunService”)

camera.FieldOfView = fieldOfView
local function onRenderStep()

local playerPosition = player.Character.HumanoidRootPart.Position
local cameraPosition = playerPosition + offset
camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)

end

runService:BindToRenderStep(‘Camera’, Enum.RenderPriority.Camera.Value, onRenderStep)

Thank you.

You can set the character’s JumpPower and WalkSpeed to 0, that way the player cannot move or move the camera.

I’m trying to get the script to follow the player’s side like a 2d runner so I want the player to be able to move.

So your problem is, the player can move away from the camera frame? If so, you can probably just weld the camera to the player’s HumanoidRootPart, set the camera part anchored to false, and set the camera part to also be massless.

robloxapp-20210416-1736260.wmv (2.2 MB)
See how when I hit the skateboard the camera goes into a top-down view but I can then move the camera. I was wondering how I would be able to lock it to its position without the player being able to move the camera.