Friday, June 26, 2026

In a client-server recreation, do it’s essential to create shopper and server implementations for all the pieces?


I’m making a recreation in Roblox Studio which has many various instruments that do various things and that is the construction I’ve selected

In a client-server recreation, do it’s essential to create shopper and server implementations for all the pieces?

Every instrument comprises an area script that initializes a ToolController

native ReplicatedStorage = recreation:GetService("ReplicatedStorage")
native Modules = ReplicatedStorage:WaitForChild("Modules")
native ToolController = require(Modules:WaitForChild("ToolController"))
native instrument = script.Dad or mum 
native controller = ToolController.new(instrument)
native ToolController = {}
ToolController.__index = ToolController

operate ToolController.new(instrument)
    native self = setmetatable({}, ToolController)
    
    self.instrument = instrument
    self.connections = {}
    
    self:Initialize()
    
    return self
finish

operate ToolController:Equip()
finish

operate ToolController:Unequip()
finish

operate ToolController:Activate()
finish

operate ToolController:Initialize()
    desk.insert(self.connections, self.instrument.Outfitted:Join(operate() self:Equip() finish))
    desk.insert(self.connections, self.instrument.Unequipped:Join(operate() self:Unequip() finish))
    desk.insert(self.connections, self.instrument.Activated:Join(operate() self:Activate() finish))
finish

operate ToolController:Destroy()
    for _, connection in self.connections do
        connection:Disconnect()
    finish
finish

return ToolController

The large battle for me proper now is definitely implementing the conduct for every instrument. Initially I used to be going to lean extra into OOP by making a bunch of subclasses of controllers and no matter, however I feel having conduct modules that I can set and swap on a single controller is healthier, however the probleem is I intend for this module to be client-sided to play animations, sounds, and ship occasions to the server for issues like harm, however does the server additionally want a server variations for ToolController and conduct module for every instrument? Or would I simply have a ToolHandler that handles every instrument? I do know that the logic must exist someplace, but it surely simply appears somewhat messy/bloated to have shopper and server scripts if I’ve 50 instruments that’d doubtlessly be ~100 scripts

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles