Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Should melee weapon script be a Script or a LocalScript?

Asked by 6 years ago

Hi guys, using a script, I'm able to deal damage to NPC without firing to the server. I also know that to damage an NPC with a LocalScript, I will need to fire to the server. What I want to know is should i go through the trouble of using a localscript and firing to the server or just use a normal script for my melee weapon? Thanks in advance.

0
Use both MachoPiggies 526 — 6y
0
I only need to use either 1 for them to work though. Or do you mean that there aren't any difference in using either of them lesliesoon 86 — 6y

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

Almost always you will want to handle user input from the client in a LocalScript, and fire the server when necessary. You should use either a Script or a module server-side along with a LocalScript.

The server cannot see a player's mouse, because the mouse is local to the player.

I encourage you to give immediate visual feedback to the client. For example, let's say we have a lasergun.

Bad approach:

  1. Player clicks to fire the wepaon.

  2. Weapon tells server, "hey, I clicked."

  3. Server creates laser part and does damage calculations.

This will look awful. The player that fired the weapon will see a visible and gross delay in the part being created.

Good approach:

  1. Player clicks to fire the weapon.

  2. Client that fires tells the server, "hey, I fired."

  3. Client that fired does calculations for the laser part locally. (And possibly damage calculations too for display purposes)

  4. Client that fired creates laser.

  5. Server does authoritative damage calculations.

  6. Server fires remotes to all players that were not the original firing player.

  7. Each client receives the remote fire and creates the laser part on their client.

The same approach can be applied to other types of tools.

Relevant article:

http://wiki.roblox.com/index.php?title=Fighting_Lag

0
I see. In your approach, 4) Client that fired creates laser. Other players wont be able to see that laser right? I've successfully made a F.E fireball script whereby I pass the server my mouse position, and created the fireball part and AOE explosion in the server script. Before this, did it locally and it didnt work online (Other people cant see it) lesliesoon 86 — 6y
0
Right, other clients wouldn't be able to see it. The server would be the one to tell other clients to do XYZ, and the clients would create them. (Also, if you feel I did answer your question, please feel free to accept them) Avigant 2374 — 6y
Ad

Answer this question