Attack & Abilities using a remote event and script / modules

Hey,

It isn’t a problem but a question about the attack and abilities system.

So i’m currently working on a small mmorpg / fighting game. All players can select and play differents heroes to fight monsters.

System Steps

1) Local Script:

It is in the “Starter Player Script”, it check when we are pressing a keybind or clicking the “Attack” button, and do a FireServer() on an Remote Event.

2) Remote Event:

It is in the “Replicated Storage”, it is used to remote the client action to the server.

3) Script:

It is in the “Server Script Service” and get the Remote Event, when activated, it check the player hero selected, the attack cooldown and active the module related to the selected hero.

4) Module:

There is a different module for each heroes, all modules are in the script.
Each module contain the code to attack and use ability related to the hero (animations, sound, damage ect…)

Capture

Questions / problems

Alright so, as you can see, only one script and some modules handle the attack of all players.

  • I’m here for it, what will happen if 2 players attack at the same time with or without the same hero ?
  • Does it will break the script or the module, because it will be played 2x at same time ?
  • Should i put the Remote Event, the Script and his Modules in the “Starter Character Script” ? then all player got their own event / scripts, and it will can’t be played 2x at same time to avoid to break the system.
  • Nothing will happen, the script shouldn’t break whatsoever or have any issues.
  • No it will not break it if it runs 2x at the same time.
  • Hell no, that’s extremely bad practice. It’s good as it is for now.
2 Likes

First things first, this topic belongs in #help-and-feedback:code-review.

Hey! I’m terribly sorry to tell you this, but if you want this to be a serious game then you are going to have to change your system workflow. With the current setup you are handling all the visuals on the server and this is bad. The reason this is bad is because anything that happens on the server is replicated to all clients so that they all see the same thing. Now, you are probably thinking: “Duh, that’s exactly what I want.” However, every single movement that happens is replicated to every client. This can cause lag and/or a slower server. For example, if I tweened a parts position on the server, every frame that it’s updated it would replicated that position to all the clients. This would not only be subject to delay, but it wouldn’t be the smoothest method either. However, if I were to do the same thing on the client it would not be subject to delay (immediate visual results), but it would also be smoother. So how do you solve this? The answer is simple! Scripted replication!

Now, I haven’t been a Roblox Developer long enough to personally use this, but there was a feature called Workspace | Roblox Creator Documentation were everything you did in a local script was automatically replicated to other clients. However, this feature was removed because there was no way to block inappropriate content from being replicated as well (hackers/exploiters). So now the only way to do this is with remote events.

You can find articles about replication on the forum. I just wanted you to know this was an option.

1 Like

Okay, thank you for the answer !

Alright, thank you i’ll go check it !

Yeah that’s true, it can do some lag but there will be only 6 to 8 players per servers, i don’t think it will lag a lot. It also is quick and small attacks, it isn’t huge and long attacks with a lot of animations so it should be okay.

I probably can do the character animation and some effect on client side and replicate it to other clients, but the majority of the attack need to be in the server side, because it add the attack 3D model in the workspace at our character position, and then it do some damages so it need to be server sided to do damages on monsters.

1 Like

It’s not actually a matter of “overloading the server” or anything like that’s, it’s lag as in latency, not low framerate. No matter how few or simple effects you’re working with, handling them on the server will make your game feel less responsive. Any time a player makes an attack, the effect will be delayed because it has to make a round trip client->server->client. First to send the signal to the server to create the effect, then back again when the effect gets replicated to clients after being created on the server. This might not show up in Studio unless you simulate latency, there’s a setting somewhere just google it. It’s handy to test if your game also feels good with latency.

1 Like

Alright, thank you for the explanation !

Does it can reduce the delay to do Server > Client instead of Client > Server > Client ?
Or something like, instead of doing a remote event from a local script, i’m putting the main script in a Gui button, and i’m directly playing the attack in server side by mouse clicking the button.

Yes it would, but you can’t do that. If you want an effect to appear when the player does something (e.g. uses an attack by pressing a button), then the server needs to know that the player has done the thing, meaning data HAS to be sent from client to server.

There might be some cases where it’s fine to detect the event on the server and then create an effect that all players see, in which case yeah that reduces latency by half a round trip compared to detecting on one of the client, but player abilities aren’t going to be one of those cases.

1 Like

This is true. The server should handle game logic, not visuals. This means that if you need to detect if a monster can be damaged, all of the logic pertaining to that (raycasting, hitboxes, ect.) should be done on the server.