OOP Rooms System - Looking for inefficient practices in my code

Hi there. So I’ve created a rooms system for a game that I’m working on with somebody else where players can create and join rooms, with 2 objects: Room and RoomPlayer. Both are utilized in the creation and interaction of a room.

Now, I’m quite new to OOP-like coding in Lua and I’m wondering if the system I have created is inefficient or impractical. Please note I have not done any code in the client, only on the server.

Here’s my current code which you can review:
RoomsSystem.rbxl (31.6 KB)

There’s some small bad practices, but here’s some of the big problems:

  • Don’t ever trust the client, your letting the client create new rooms and joining random ones. The client could spam these remotes and drag the server performance down.
  • Your creating lots of remotes manually, use network modules to make it easier.
  • Missing comments, not all code needs comments. But this one does, try explaining why its there and if its hard to read what it does.
  • Make more constants, your defining values as you go, try defining them at the top of the script.

Some things could be shortened, but other than that its all good.

I am indeed following this rule, and as you can see in my code, I took appropriate measures to ensure clients can’t exploit the system easily. While I do agree with the server performance, Remote Events exist for a reason. xD

Something like ReplicaService perhaps?

Will do!

I don’t exactly understand this bulletin, could you try explaining this in further detail?

Anywho, thanks for the feedback. I appreciate it.

There’s many times you define a value in an important place. Making constants (variables at the top of your script) and then referencing them there helps clean it up, and provides an easier way to change them.

Before:

-- ...

TeleportService:ReserveServer(...)

After:
local ServerPlaceId = ...

-- ...

TeleportService:ReserveServer(ServerPlaceId)
1 Like