This script won't work

I’m trying to make a local gravity using an overlap sphere that pulls in objects.
However, I can keep getting errors with this script.
Thanks.

public float pullRadius = 2;
public float pullForce = 1;
public Rigidbody rb;

void Start() 
{
	 rb = GetComponent<Rigidbody>();
}

public void FixedUpdate() {
	foreach (Collider collider in Physics.OverlapSphere(transform.position, pullRadius)) {
		// calculate direction from target to me
		Vector3 forceDirection = transform.position - collider.transform.position;

		// apply force on target towards me
		collider.GetComponent<Rigidbody>().rb.AddForce(forceDirection.normalized * pullForce * Time.fixedDeltaTime);
		}
	}
}

The thing that strikes me as problematic with this code snippet is this line:

collider.GetComponent().rb.AddForce(forceDirection.normalized * pullForce * Time.fixedDeltaTime);

I don’t think you want to have that .rb in there; you already have a reference to the rigidbody you are trying to apply force to, you should be able to just do:

collider.GetComponent().AddForce(forceDirection.normalized * pullForce * Time.fixedDeltaTime);

Alternately, rather than doing a GetComponent, you could use the .attachedRigidbody property on the collider.

Also, in the future, when posting questions on Unity Answers please give them a specific title that explains your issue, and provide any errors or incorrect behavior so people can help solve your problem. That way other people with similar issues can find your question and the solution within.