How to improve code?

Something immediately apparent is you are setting the parent of instances before setting properties:

local VPFcam = Instance.new("Camera")
VPFcam.Parent = accessoryViewport
VPFcam.CFrame = CFrame.new(0, 0, 0)

This is bad practice, you should always set properties before parenting an instance. This post into more detail and explains it better than I could as to why we do this: