Player Not Colliding 3D

I am working on a 3D game, and there is a railing I want to put that will stop the player from going out of bounds. But the colliders don’t stop each other when they touch. I have a capsule with a capsule collider for the player, and a box collider for the railing.

Here’s my movement code:

public class PlayerMovement : MonoBehaviour
{

    public float moveSpeed = 5f;
    public Rigidbody rb;
    Vector3 movement;
    
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //Input
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.z = Input.GetAxisRaw("Vertical");

    }

   
    private void FixedUpdate()
    {
        //Movement
        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }
}

Change it to this code

public class PlayerMovement : MonoBehaviour
 {
 
     public float moveSpeed = 5f;
     private Rigidbody rb;
     Vector3 movement;
     
     
     // Start is called before the first frame update
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     // Update is called once per frame
     void Update()
     {
         //Input
         float moveHorizontal =  Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");

         // SET YOUR VECTOR HERE
         movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
 
     }
 
    
     void FixedUpdate()
     {
         //Movement
         // MOVE POSITION WILL ONLY MOVE IT ONCE!
         rb.AddForce(movement * moveSpeed);
     }
 }

This code is 100% better and your own code is so wrong man also private void FixedUpdate() won’t work!!

Does your “railing” have a rigid body component? and is it a cube?

Also, try using:

void OnCollisionEnter(Collison object)
    {
         debug.log(object.collider.name);
    }

This will check if your object is being collided with your railing or not.