This probably won’t solve your problem, but I noticed that in your code you parent the beam within the Instance.new() call.
Awhile ago it was discovered that this can lead to some serious efficiency problems and it is recommended that you parent objects after setting all of their properties, like this:
local beam = Instance.new('Part')
-- Set all of the properties like BrickColor, Anchored, etc.
beam.Parent = game.Workspace
Hopefully that will be helpful in the future!