do most developers require services at the top of their scripts or do they have a services module that they require? i made a services module earlier as i thought that it would speed up my workflow but i’m not too sure if it would effect game performance.
for instance:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ScriptUtilities = ReplicatedStorage:WaitForChild("ScriptUtilities")
local Services = require(ScriptUtilities:WaitForChild("RBLXServices"))
Services.Players.PlayerAdded:Connect(function(Player)
end)
Since I mainly use module scripts, I have one module script that will have every service and utility script that I will use (in most situations) and then will copy and paste the script into wherever it is needed
I don’t exactly know what you mean by services module but if you mean something like a module loader where a modulescript requires every module script then puts them in a sharedtable so it is able to be access by any script, is very useful for organisation as it avoids potential require loops and avoids memorising where scripts are in the hierarchy
In theory, a module would be more performant since it caches all the services, but I believe GetService calls already cache themselves? Someone would have to fact check that.
Most developers (including Roblox themselves according to the style guide) prefer to require services at the top of the script. If you want to speed up your workflow, I’d recommend a plugin like SimpleComplete.
Unless I misunderstood, duplicating a module defeats the entire purpose of using modules in the first place. Choose a location such as ReplicatedStorage and require the same module in every script you want to use it in.
Also, he meant having a module that has all the services (replicatedstorage, etc) in them. Read the code example.
This is stupid, using :GetService() you can get the service in 1 line instead of 3.
So no this absolutely doesnt speed up your workflow and you should rather do something like this;
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
--Code
end)
(please tell me this is ragebait or a joke, this cant be serious)
i would do that if it was only 1 service but if i need to get 10 services across 100 different scripts then its kinda annoying.
i can just do this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Services = require(ReplicatedStorage:WaitForChild("RBLXServices"), true)
Services.AdService
Services.AnalyticsService
Services.AnimationClipProvider
Services.AssetService
Services.AvatarCreationServicr
Services.AvatarEditorService
Services.BadgeService
Services.BrowserService
Services.CaptureService
instead of this:
local AdService = game:GetService("AdService"),
local AnalyticsService = game:GetService("AnalyticsService"),
local AnimationClipProvider = game:GetService("AnimationClipProvider"),
local AssetService = game:GetService("AssetService"),
local AvatarCreationService = game:GetService("AvatarCreationService"),
local AvatarEditorService = game:GetService("AvatarEditorService"),
local BadgeService = game:GetService("BadgeService"),
local BrowserService = game:GetService("BrowserService"),
local CaptureService = game:GetService("CaptureService"),
No no no please just stop with this nonsense
your method is still longer, everytime you want to use a service you need to type Services.AdService instead of just adService.
Stop trying to be special nobody does this.
I would check this out. If you’re just too lazy to type them out, this does help a bit. I use it myself and you really don’t have to worry about services after this. Much better than what you’re doing imo