I’m a newbie scripter in Roblox Studio, and after going through a few tutorials, I’ve started working on creating a simple game. In this game, players enter different levels and battle various monsters using different weapons.
Could you please advise me if I understand the programming approach in Roblox correctly? In short:
Various types of monsters randomly appear on the level.
Each player can attack them, and multiple players can also attack together.
I’m a bit concerned because in my solution, there are quite a few events, and I’m not sure how it will behave with a larger number of players and monsters as I continue developing the game.
Here’s how I plan to solve it:
Monsters are spawned on the level.
Information about monsters and their HP is stored in ServerScriptService in the module MonsterHolder.
The client side knows nothing about MonsterHolder, so events need to be used.
Now I have something like this:
One event that sends the amount of damage dealt to the server (everything is calculated in MonsterHolder).
One event that sends the remaining amount of the monster’s HP from the server.
And some event that removes the monster when its life drops to zero.
Firstly, am I combining things correctly? Secondly, will Roblox handle a larger number of such events? Currently, it’s only monsters, but later there might be shops, purchases, and other add-ons.
This is largely dependent on your usecases, but usually it would be fastest and easiest to use the tools at your disposal to their full potential.
In this case: humanoids.
They store their health, you’ll only need to handle monster spawning and respawning using references/events in your script.
This would handle monster HP replication to clients for you.
Only thing you need to implement is an event that damages the humanoid Server-Side.
What you’re doing currently is fine. Though, I recommend if you’re using humanoids for the monsters, then just use the humanoids to read the changes of the health property, so your module doesn’t have to do that. You should use another event to check if the player hitting the monster is legal before it actually damages the monster, so it can keep things secured and clean from exploitation.
Roblox can handle a larger number of such events, depending on what those events are for. Since events still check if the remote has been received by the server, it can lead to some extra latency on top of the player’s network latency.
Long version of my TL; DR
There are some things I would like to ask before I say whether you’re doing it “wrongfully” or not, since I’m still unsure about how your place is set up prior to making up this system. And before I ask you, please note that there’s really no right way of doing things. There may be things you can optimize within your code(s) to enhance your workflow and readability. But even if the script is mumbo jumbo, if it helps create the exact thing that you wanted, then so be it.
Would you be using monsters with humanoids, or ones with an animation controller? With a humanoid within the entities, it might make your coding more simplistic than it is right now. If the monsters have humanoids, you can just simply check their health from the humanoid itself, when its health changes. It would keep the amount that you’re scripting as simplistic as possible, since you wouldn’t need the module to store its current health. Just would need to send the current health to the players with a remote.
But, you will need a script to check if the player is legally hitting the monster. (If you’ve not thought of that already) Combat games like this needs that in place to prevent possible exploitation, where they could be hitting the monster 40 distances away or whatnot, which will mean another remote to handle that. And depending on what you want to happen when they do get verified, RemoteFunctions might be useful to yield a part of the code and see if the server validated their damage input.
Apart from these points, I think the way you’re doing this is just fine. It seems like you’re in the right way of going around the server ⇾ client communication for this type of game.
And to answer your question if “Roblox will handle many events firing”, for the most part, it can. It’s designed to give a lot of data to the server in a matter of miliseconds. Though, it can become a bit much for the server’s performance if there’s a ton of users sending a remote at once, where the server has to process that data heavily. Especially because the remotes will still require some network transfer between the client and the server, which would be a problem for some functions that doesn’t need to check if the remote had been set and received by the server the exact moment it was fired. If that were the case, then I also suggest you looking at UnreliableRemoteEvents. It’s like a RemoteEvent, except it takes away that security of if the packets of the remote has been received or dropped, which is what causes the extra bit of latency. It will allow for some asynchronous and unordered fired events, but it wouldn’t matter if the data isn’t too lethal to the general gameplay. (Like, if values are being updated every frame that doesn’t matter to the main gameplay, like a number increasing by 1 every heartbeat.)