Sup, I recently was making a module script that communicates the server with the client with the use of remotes, but I’m not too sure if it’s good or bad, I want to know if what im doing is right and better ways of doing it.
Heres my way of doing it:
The module (unfinished)
local module = {}
local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local remoteFolder = script.Remotes
local remotes = {}
for _, remote in remoteFolder:GetChildren() do
if remote:IsA("RemoteEvent") then
table.insert(remotes, remote)
end
end
remoteFolder.ChildAdded:Connect(function(child)
if child:IsA("RemoteEvent") then
table.insert(remotes, child)
end
end)
-- [[ CLIENT ]]
if RunService:IsClient() then
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
remotes.SetCamToPartEvent.OnClientEvent:Connect(function(camPart:BasePart, tweenInfo:TweenInfo)
end)
end
-- [[ SERVER ]]
if RunService:IsServer() then
function module:SetCamToPart(plr:Player, camPart:BasePart, tweenInfo:TweenInfo)
remotes.SetCamToPartEvent:FireClient(plr, tweenInfo, camPart)
end
end
return module
I see no purpose in this as you are just putting the remotes events inside a table from a folder. It seems you are repeating the same process you would do with less steps from a normal script.
It seems like you’re trying to abstract away remote events (in a questionable way).
The only thing I have to say is that there’s no reason to have the table there. You already have a table, the folder with the remotes, you can just do remotesFolder.YourRemote instead of keeping another table in memory, and wasting some time adding everything to that table.
You can cut that part out and it would look like this:
local module = {}
local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local remotes = script.Remotes
-- [[ CLIENT ]]
if RunService:IsClient() then
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
remotes.SetCamToPartEvent.OnClientEvent:Connect(function(camPart:BasePart, tweenInfo:TweenInfo)
end)
end
-- [[ SERVER ]]
if RunService:IsServer() then
function module:SetCamToPart(plr:Player, camPart:BasePart, tweenInfo:TweenInfo)
remotes.SetCamToPartEvent:FireClient(plr, tweenInfo, camPart)
end
end
return module
I would just use normal remote events, since this doesn’t really abstract away anything. You still need to add event handlers and functions to the module every time you add a new remote. The only difference is that you require a module instead of referencing a remote.