Within one of the games I’m designing, there’s several non-movement buttons the player can press to preform different actions (i.e. “Q” to block, “E” to dash, etc), all of these remote events are stored in the player and are communicated via localscript to the serverside scripts to execute the actions. Would it be better to have one massive script to receive and preform the actions, or would it be better to have a script for every individual action? Personal testing shows that there can sometimes be delays within the same script when it comes to running several functions as one must be completed before the other, however I fear that too many separate scripts could create lag with many players.
I’m fairly green when it comes to development and I’m unsure which way to tackle the situation. Any advice is appreciated.
TL;DR: Handle the receipt of remote events within one main script or individual scripts per event?
It doesn’t really matter but for the sake of organization, I like to handle all of my related remotes in a single script.
For example, this script handles remotes related to data (eg. tutorial progress, settings)
skipTutorial.OnServerEvent:Connect(function(player)
local data = playerData:WaitForChild(player.UserId)
local leaderstats = player:WaitForChild('leaderstats')
local stage = leaderstats:WaitForChild('Stage')
local tutorialInfo = data:WaitForChild('TutorialInfo')
for i,v in pairs(tutorialInfo:GetChildren()) do
v.Value = true
end
if stage.Value <= 9 then
stage.Value = 9
end
end)
tutorialPart.OnServerEvent:Connect(function(player, type)
local playerData = playerData:WaitForChild(player.UserId)
local tutorialInfo = playerData:WaitForChild('TutorialInfo')
tutorialInfo:FindFirstChild(type).Value = true
end)
submitSetting.OnServerEvent:Connect(function(player, settingName, settingValue)
local data = playerData:WaitForChild(player.UserId)
if not data then
return
end
local settings = data:WaitForChild('Settings')
local setting = settings:FindFirstChild(settingName)
if setting then
if type(settingValue) == 'table' then
for i,v in pairs(settingValue) do
local obj = setting:FindFirstChild(i)
if obj then
obj.Value = mathUtil:RoundToThousandth(v)
end
end
else
setting.Value = mathUtil:RoundToThousandth(settingValue)
end
end
end)