How would I insert line force to all parts inside workspace?

I’m not asking for an entire script I’m asking if some one could lead me into the correct direction to allow me to give every object a line force which attaches to every other object, as I’m attempting to make my own gravity simulator.

I have searched everywhere for any info and I couldn’t find anything. so what I did was try to put the attachments that are made into a table and then create a new line force that attaches to every object but that hasn’t worked out for me.

(sorry if the post isn’t that good its my first time posting)

pseudocode:

for every part P in the workspace

	initialize a vector F = 0, 0, 0

	for every other part Q in the workspace
		get the unit vector of the direction that P points to Q (position of Q - position of P)
		multiply the unit vector by (mass of P * mass of Q * an optional constant G) / (dist between P and Q) ^ 2
		add the resulting vector to F

	apply the total force F to part P (or accelerate by F / mass of P)

If this is being repeated several times each second, divide F by the physics rate before applying it to the part.

would this be inside the part or inside workspace? And also I already have a script to create the gravity