Tool/RemoteEvent Organization

What is the best way to approach making a game that has multiple tools and events?
An example would be a game that has the following tools: Axe, Pickaxe, Sword.
Normally I would create a serverscript in serverscriptservice for each tool, so AxeScript, PickaxeScript, and SwordScript, I would also then create a remoteevent for each tool, so AxeEvent, PickaxeEvent, and SwordEvent. What is the best way to go about doing this because I feel like mine isn’t the best for performance or readability.

1 Like

You could just put each ServerScript and RemoteEvent inside of the tool, placing the tool in the StarterPack. Then, using a ClientScript inside of the tool, you can get the tool.Equipped event and then fire the RemoteEvent, connecting it to the ServerScript.

This way, all of you scripts and events are kept in one place and function the same way.

2 Likes

The only thing I really care about is performance, so I just want the most optimal way.

1 Like

This would work just as fast as any other solution. You are ultimately trying to get a client’s input sent to the server. Using a RemoteEvent would be the fastest and most efficient way to do that in this case.

Generally, it shouldn’t matter where your instances are located, as long as your ServerScripts don’t end up in places like StarterPlayerScripts and vice-versa.

Your proposed idea would be just as efficient as mine. My solution is more generic for Tools, as everything is contained inside of one model.

1 Like

So I don’t have to worry about, using the same script for each tool? But what if 2 players fire the event at the same exact time?

1 Like

I am not entirely sure what you mean by “the same script for each tool”. You would only have a LocalScript, ServerScript, and a RemoteEvent in the tool.

The LocalScript would get the client’s input and fire the RemoteEvent.

The ServerScript would detect when the RemoteEvent is fired and then manage the tool based on the info the client sent.

If 2 players fire the event at the same time, the ServerScript would still detect both of the event fires and deal with them. The server can run multiple events at the same time. When an event is fired to the server, you can compare it to task.spawn(). It essentially just creates a new task on the server.

1 Like

put a single server script in serverscriptservice and a remote inside the tool, use collectionservice to reference all the tools in the game in a single server script

2 Likes

Make sure you check if the owner of the tool is the one firing the remote event. This is also a pretty unorganized solution as modifying an entire tool system means going in each tool and changing the script. Instead, use a module script with generally used functions/events. Detect if the tool has a special callback for each event by checking for the presence of a package module script with a table of functions and if needed. This means all your tools will be sharing just 3-5 remote events!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.