How can I make it so that the ui is not replicated to the other clients(server)?

If Guns are pawns then you can get their controllers and check it the same way (make sure to validate controllers, as other players’ guns on clients won’t have their controllers).

But general rule is that controllers should be responsible for player UI. If you have different UIs per gun, you could send UI class to the controller and create it there. It’s easier to manage.