What is the most efficient way to solve this problem?

Straight to the point, Let’s take minecraft’s system as an example here since it closely resembles what im trying to achieve. In minecraft, u have different items which when clicked do a specific thing or function. I know how to script this but what is the best way to approach this?

Shud I create a localscript parented to the certain item and code my behaviour there?

Or, shud i make a modulescript which contains function for all the specific items and run it whenever the right mouse btn is clicked with the item being equipped?

Or better yet, is there a much efficient solution tht i havent thot of yet?

im not asking for full code, juz the main idea

I would go the OOP route for an idea like this.

Modulescripts 100%
You could easily make a system that fires a remote when the right mouse button is pressed, and then from that you can find and run the code related to the thing that would be used

1 Like

I decided on tht approach first but wudn’t it make the script messy if,say, i had lik around 20 items?

If you just organized it well then no not really, i do that for my effects and it’s not messy at all

Oop seems unnececessary, if u personally asks me since it isnt like an inventory system or anything.

Well tbh it seems lik my best bet rn.

Expanding on what @BopperDuppet said, if you want to perform an action like opening a door, the best method would be as follows:

  1. Create a way to get the position and object or terrain cell hit by the players mouse.
  2. Have a way a detecting if the object hit can perform an action (perhaps through Instance Attributes | Roblox Creator Documentation or CollectionService | Roblox Creator Documentation)
  3. Assuming the object has an action tied to it, you can get that action (function) from a predefined table and perform it on that object on the client.
  4. Fire a remote to the server and have it replicate the action to other clients.

Still, CollectionService would be the best method.

1 Like

Could u elobarote abt the predefined table part?

Nvm i got it.

That was mostly if you used Attributes. You could have a string and then, upon getting that string, check a dictionary and see if it has a function for it.