Soo the question is in title, i have no idea how i could implement remotes later in my OOP artillery to control mouse and inputs signals, i don’t want to use single remote because if it will be fired by every player it could lag entire game, any ideas?
I don’t think that I understood this well
do you mean smt like this?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local module = {}
module.__index = module
function module.newClass()
return setmetatable({}, module) -- oop class
end
function module.FireRemote(...)
ReplicatedStorage.RemoteEvent:FireServer(...) -- oop remote
end
return module
No, i asked about how i should store remotes itself in OOP, should i use remote per object or only one remote event per class ect. i have problem with this
Keep them as variables outside any functions so they are more accessible later, or insert them into the class you made.
problem with this aproach is that they cannot be accesed by client
something like this?
local module = {}
module.__index = module
function module.newClass(remote :RemoteEvent)
local self = setmetatable({}, module)
self.remoteEvent = remote
return self
end
function module:FireRemote(...)
self.remoteEvent:Fire(...)
end
return module```
Why not??
Modules can be accessed by server or client??
local module = {}
module.__index = module
function module.NewClass(Remote : RemoteEvent)
local self = setmetatable({}, module)
self.RemoteEvent = Remote
self.RemoteEvent.OnClientEvent:Connect(function()--Client Listens????
print("Hello")
end)
return self
end
return module
but wouldn’t storing remote inside every object/model not performant? i mean imagine that every player will build artillery, i need to handle about 20+ functions of controlling this artillery movement like 12 times per second, this is a lot
they can, but objects that they create are different, soo there will be 2 remotes, one server sided and one client sided, you need one to send and receive messages
what about having 1 object value inside every artillery that will point to a remote?
That’s what remote functions are for.
still idk if you understand me, my problem is to how store remotes, if i should use one remote and determine which artillery player uses (for example by where player is sitting) or should i use multiple remotes in every OOP object
I use this remoting class, which constructs a new remote for each route.
Client
function AvatarEditorClient:PromisePromptBuyAll(outfitInst, assetsToPurchase)
assert(typeof(outfitInst) == "Instance", "Bad outfitInst")
assert(type(assetsToPurchase) == "table", "Bad assetsToPurchase")
if #assetsToPurchase == 0 then
return Promise.rejected("0 items in order")
end
return self._remoting.PromiseBuyAll:PromiseInvokeServer(outfitInst, assetsToPurchase)
end
Server
function AvatarEditor:_setupRemoting()
self._remoting = self._maid:Add(Remoting.new(self._obj, "AvatarEditor", Remoting.Realms.SERVER))
self._maid:GiveTask(self._remoting.EquipAssetId:Bind(function(player, ...)
return self:PromiseEquipAssetId(player, ...)
end))
self._maid:GiveTask(self._remoting.PopupVisibleChanged:Connect(function(player, isPopupOpen)
assert(player == self:GetPlayer(), "Bad player")
self._data.PopupOpen.Value = isPopupOpen
end))
self._maid:GiveTask(self._remoting.EquipBundleId:Bind(function(player, ...)
return self:PromiseEquipBundleId(player, ...)
end))
self._maid:GiveTask(self._remoting.UnequipAssetId:Bind(function(player, ...)
return self:PromiseUnequipAssetId(player, ...)
end))
self._maid:GiveTask(self._remoting.UnequipBundleId:Bind(function(player, ...)
return self:PromiseUnequipBundleId(player, ...)
end))
self._maid:GiveTask(self._remoting.SetBodyColorsData:Bind(function(player, ...)
return self:PromiseSetBodyColorsData(player, ...)
end))
self._maid:GiveTask(self._remoting.SetOutfitFromUserId:Bind(function(player, ...)
return self:PromiseSetOutfitFromUserId(player, ...)
end))
self._maid:GiveTask(self._remoting.UnequipInventorySlot:Bind(function(player, ...)
return self:PromiseUnequipInventorySlot(player, ...)
end))
self._maid:GiveTask(self._remoting.UnequipAll:Bind(function(player, ...)
return self:PromiseUnequipAll(player, ...)
end))
self._maid:GiveTask(self._remoting.PromiseBuyAll:Bind(function(player, ...)
return self:PromisePromptBuyAll(player, ...)
end))
end
soo you create remote per every object class and you store it in replicated storage, model or somewhere else right?
Yup. In this case, each player gets their own.
This really helps with security because we can do very simple assertions at the top. There’s a very small perf cost, but it’s effectively neglectable.
last question, where do you store those remotes soo both client&server can access them at the same time and know which is which?
That’s a Configuration object, but it’s literally just there so the remotes get sorted to the bottom of the explorer.
You can use a folder or anything else.
But you name them with player UserId or smth to determine which is correct? sorry but i never worked with OOP replication and it’s kindof yk, new…
No, I construct a new “AvatarEditor” for each player, with the object referencing the player (well, actually that Folder named “AvatarEditor”.
Then the object just does the equivalent of self._myFolder.Remotes.MyRemote:FireServer()
Note that the remoting object I linked above abstracts all of that.
Now i understand, soo create remote events storage on server that points to specific player,object,model or anything and use references & instances to fire remotes, thx for help Quenty :}