I'm trying to get a black sludge on ultra sun but whenever I use thief on the Pokemon that can have it, they mainly faint so I am worried that this is preventing me from getting the item.
Yes it will still work.
I know this from experience, as I used this method to get Heart Scales from Luvdisc in ORAS, and I doubt the mechanics have changed since then. I suggest leading with a Pokemon with the ability Frisk, though, as it will mean you are not wasting your time attacking Pokemon that aren't holding an item.