Camera Manipulation Help

I’m currently creating a saber system that allows better PVP improvements. Though I’m up to a part which I’m stuck with.

I’d like to allow my character to press E within a range of a character and it locks onto the victims torso or head. I’ve gotten up to the part which I need a function to lock onto the victim character, though I do not know where to start or where I’m messing up.

I tried camera manipulation for the first time and I got the camera to position itself above my characters shoulder, although the camera locks and not focusing on the character. Please point me in the direction to help complete this part of the system. Here’s what it looks like so far-

local RunService = game:GetService("RunService");
local UserInputService = game:GetService("UserInputService");
local Players = game:GetService("Players");

local Player = Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Mouse = Player:GetMouse();

local Camera = workspace.Camera;

local Target;
local Toggle = false;

function SetFocus(Delta)
	if (Target and Character:FindFirstChild("HumanoidRootPart")) then
		Camera.CFrame =, Target.Position);

UserInputService.InputBegan:Connect(function(Input, gpe)
	if (gpe) then return end
	if (Input.KeyCode == Enum.KeyCode.E) then
		Toggle = not Toggle;
		if (Toggle) then 
			Mouse.TargetFilter = Character;
			Target = Mouse.Target;
			RunService:BindToRenderStep("Focus", Enum.RenderPriority.First.Value, SetFocus);
			Target = nil;

This is what it should be like (I think).
I didn’t plan to make this a “final product” but this should guide you to your goal.


This is exactly what I was looking for, thanks for the help!

1 Like