Datapack not working as expected when put onto a server

Hi, I have created a datapack that works perfectly fine when I run it in single player but as soon as I put it onto the server it doesn't work as expected.

What my datapack does so far is it modifies villagers trades so that when the player buys from the villager it spawns in a build with the place command. That works all well and good. The issue that I have with it is that I have to trade with the villager twice before it actually works. Whereas on single player it is only one trade. Also the trade on the server doesn't take the items from me that I use to buy the build upgrade. Any ideas on what could be going wrong here? The server is running paper. I have tried it separately on a different paper server with no other stuff running and the same thing happens. I did also try it on a fabric server and it worked as intended. I'd rather not swap everything over to fabric as there are certain plugins that we use that are not on fabric. I hope you can help me, thanks

Continue to help post