I have currently just one remote event under the the replicated storage and it handles all my events when it comes to things like purchases from the shop. I also have one remote event under each tool I add to my game. I see a lot of people use remote events in different ways. Some use many for each buy event and other even put them under different places like workspace. Is one remote event enough for handling all the purchases in game? How does it affect loading to have more than one? Ultimately what is the best practice when dealing with remote events?
"Some use many for each buy event and other even put them under different places like workspace."
This is just your choice of organization. If you can make do with only one RemoteEvent for all purchases, great! But if you find it easier to split it up into multiple RemoteEvents, that's perfectly fine too. Adding a RemoteEvent (or even 10s or 100s of them) to your place shouldn't impact performance in any noticeable way. A RemoteEvent should take significantly less time than a Part to load, and shouldn't impact performance once its loaded (unlike Parts, which impact collision, physics, and graphics, depending on if you're looking at the server or the client).
Note that if you wanted, you could make do with a single RemoteEvent (though I do not recommend this). ex, if you have a LevelFinished(levelNum)
and a PurchaseItem(itemID)
event, you could merge them into a generic Event(eventID, eventData)
. On the server, you would need a dictionary mapping an eventID to the function that can handle it. This is a lot of extra work (for both you and the server) compared to just making separate RemoteEvents!
On the other hand, if you're thinking of making 10s or 100s of RemoteEvents that aren't going to be used by all players (just a few of them), I would recommend considering simplifying them.
"Ultimately what is the best practice when dealing with remote events?"
In terms of count, do whatever makes sense (ie use as many as you need). More important than the number of events, however, is how secure they are. An exploiter/hacker has the ability to activate any RemoteEvent with any value they like - including ones you didn't intend. Check out this guide for more information and spend some time thinking about what happens if someone sends either subtly wrong or completely random arguments to your RemoteEvents/Functions. It may also be good to keep track of how many times any one player activates a RemoteEvent/Function and kick them if they're spamming it -- ex, if someone activates a RemoteEvent 600x/minute and you are sure that your scripts never activate it more than once per second (60x/min), you've found a hacker.