How to get camera centered but moves with players?

Im trying to make a 2D style fighting game and i have the whole 2 players are in view of the camera, but how do i lock the position of the camera to a part while still being able to move slightly for movement?

while wait() do
	if script.Parent.Play1.Value ~= "" and script.Parent.Play2.Value ~= "" then
	local hrp1 = game.Players:WaitForChild(script.Parent.Play1.Value).Character:WaitForChild("UpperTorso")
	local hrp2 = game.Players:WaitForChild(script.Parent.Play2.Value).Character:WaitForChild("UpperTorso")
	local averagePosition = (hrp1.Position + hrp2.Position) / 2
	local cameraPos = workspace.CurrentCamera.CFrame.p
		workspace.CurrentCamera.CFrame = CFrame.lookAt(cameraPos, averagePosition)
		end
end

I’ve done something like that before. Hopefully this helps, feel free to mess with the numbers to how you like:


local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")

camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Attach
camera.FieldOfView = 70

game:GetService('RunService').Stepped:Connect(function()
	camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,20,40)
end)

How would I attach this to a regular part tho almost like a mario kind of feel?

Oh yeah, you MUST make sure it’s a local script inside of StarterPlayerScripts and it MUST be titled CameraScript

Yo, uh this has been awhile. Did my script solve your problem?