Code works but is kinda slow

Hi! I am trying to make a custom platformer camera, and I made this. It works, though it kinda lags behind the player. This script spawns a part that follows you player and your camera goes to this part. What I am trying to do is make the part not lag behind the player. This is inside serverscriptservice BTW

--Variables--
local Players = game.Players
-- Join script
Players.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Char)
		local HRP = Char.HumanoidRootPart
		local CamPart = Instance.new("Part",workspace.CamParts)
		CamPart.Anchored = true
		CamPart.Name = Plr.Name
		CamPart.Transparency = 1
		while wait() do
			CamPart.Position = Vector3.new(HRP.Position.x,HRP.Position.y, HRP.Position.z+20)
		end
	end)
end)

Here is the camera script. I know it is probably the waitforchild inside the loop, but i found it is the only wayit works.

--Variables--
local Player = game.Players.LocalPlayer
local Camera = workspace.Camera
local CamParts = workspace.CamParts
--Cam script--
Camera.CameraType = Enum.CameraType.Scriptable
while wait() do
	local CamPart = CamParts:FindFirstChild(Player.Name)
	if CamPart then
		Camera.CFrame = CamPart.CFrame
	end
end

This is because you’re running a while loop indefinitely. Especially in Lua, but also in other languages, it’s best to avoid infinite while loops as they hang the current thread and continually use up performance. Luckily, you can hook this up with an event to check when HRP’s position changes:

HRP:GetPropertyChangedSignal('Position'):Connect(function()

    CamPart.Position = Vector3.new(HRP.Position.x,HRP.Position.y, HRP.Position.z+20)

end)

This will not only let the current thread run, but it also is much faster than while loops.