Quick question about object oriented programming

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a module that uses OOP via requiring from modulescript. I am thinking about making one for both the server and client to use, but I have heard that modules can’t be uses by both the client and the server. I don’t know if this applies to object oriented modules, what I mean is both scripts require and both make their own object.
  2. What is the issue? Include screenshots / videos if possible!
    Idk if I can or if I can’t.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    There is barely anything related to OOP on the dev hub. I have searched it up here, and I haven’t found anything.

This is a just a simple scripting-related question that can help me optimize my scripting better.

You can require the same module from both server and client. To know if the module is running in the server or in the client, you can use RunService:IsClient() or RunService:IsServer()
You can know more about RunService here.

1 Like

It is very much possible to interact with module scripts with the client and the server. This is actually very useful for creating placement systems in which you must move an object on the client and clone the object in the server for everybody to see.

There are many instances when you might use module scripts to interact with the client and the server using OOP :slight_smile:

1 Like

I know, but I am saying the same object. I am basically asking if I could require the same module script object and would it be possible.

Hmm, yeah about this between the client and server it actually might be possible as you know OOP in Roblox utilizes meta tables as explained in the tutorial in order to store the properties and methods of the object like car wheels = 4, and Car:MoveForward() and such.

However, as we know because filtering enabled the client and server are essentially separated and have to communicate with each other using remote functions and events like the dev reference API for the most part save for some exceptions like physics.

Then there comes a problem if we want to create an object on a client and replicate it to the server due to this meta table constraint according to the dev api reference.

If a table has a metatable, all of the metatable information will be lost in the transfer. For example, when the server receives the following table, the truck table that was passed will have the Name property but not the NumWheels property that was part of the Car metatable.

Consequently, yeah it’s possible for the client to share the same properties and methods with the server but it’ll be hard and require extensive networking.

It might be better to use inheritance in order to create two new objects scripts from the original master object, one defined for the client and one defined for the server plus you can see the furniture placement example in the resource thread there: