Behold: Lazy People's Game Services Module!

I have created a module for lazy enough people who cannot type game:GetService(service) or for people who are really into Module Scripts!

(CLICK TO DOWNLOAD) (717 Bytes) If you need to call a module to have multiple services at once:

  1. Why?
  2. You are in luck!

This script has multiple handy services such as BadgeService, TweenService and Debris, or lesser known and way stranger ones such as BrowserService or AdService

(If you have a suggestion to add a service to this module just tell me!)

Here is the code if you do not want the file in your PC (copypaste)
local services = {
	ServerScriptService = game:GetService("ServerScriptService"), --Sometimes this service does not appear for some reason
	CoreGui = game:GetService("CoreGui"), --CoreGui such as the loading screen, the default icons top bar, the inventory GUI, etc. that is roblox default
	MouseService = game:GetService("MouseService"), --This service can be useful for pointers needed in guns
	MessagingService = game:GetService("MessagingService"), --You can send server messages
	PhysicsService = game:GetService("PhysicsService"), --Has to do with collision groups
	PermissionsService = game:GetService("PermissionsService"),  --Gets the type of role you have in roblox groups
	DataStoreService = game:GetService("DataStoreService"), --Everything that can be stored in the cloud
	BadgeService = game:GetService("BadgeService"), --Badges, obviously
	TweenService = game:GetService("TweenService"), --Animations galore!
	Debris = game:GetService("Debris"), --Schedules at what time you need to remove something without placing too many scripts
	BrowserService = game:GetService("BrowserService"), --Browse someting trough HTTP requests I think (I don't know, I am getting these from the roblox vlogs)
	HttpService = game:GetService("HttpService") --Send and recieve signals to websites outside of roblox
}

return services

One reason you would use this is that, you would not have to call game:GetService() on different scripts just to get the same function

Need to call the module? Just use require()!

Updates
[details= "Version 1.0"]
This module script has been added for the first time!
- 2/17/2021
[/details]
Version 1.1

Added a copypaste version of the script, and some services were removed since they were either terminated or documented, leaving a trace in game:GetService()

  • 2/17/2021
6 Likes

Thank you for this contribution :slight_smile:

7 Likes

Could you create the following for this module?

  • Open sourced GitHub or Pastebin of the code
  • Documentation
  • Example usage (Easiest)

If you used a metatable for this, it’d have access to any service (at the cost of losing intellisense). Here’s a basic example of what I mean:

GetService Module:

local GetService = setmetatable({}, {
	__index = function(_, service)
		return game:GetService(service)
	end,
})

return GetService

Script:

local Services = require(path.to.GetService)
local ReplicatedStorage = Services.ReplicatedStorage

-- do stuff...
7 Likes

Inefficient, your idea is great, but that would be using :GetService() every time.

I’d use:

local Services = setmetatable({}, {__index = function(Self, Index)
	local NewService = game:GetService(Index)
	if NewService then
		Self[Index] = NewService
	end
	return NewService
end})

return Services
3 Likes

The question is why? How does requring an module is apparently way faster than just like calling one function?

it isn’t, and to me it seems like much more of a hassle than just using game:GetService()
you may want to try something like this, which doesn’t require you to require() a module each time:

local services = {}

local function getService(name)
	-- GetService errors if an invalid className is provided
	-- don't handle that case because you want to see that error
	local service = game:GetService(name)
	services[name] = service

	return service
end

setmetatable(_G, {
	__index = function(_, name)
		return services[name] or getService(name)
	end
})

print(_G.RunService) --> Run Service
print(_G.CollectionService) --> CollectionService
print(_G.FakeService) --> 'FakeService' is not a valid Service name
1 Like

Now you do not have to call different functions on different scripts, now it’s all in one module!

It’s all in one module! why wouldn’t you?

Because it is Way slower firing 2 functions just to require one module and over 20 indexes/functions just to get that one GetService.

It is like "Hmmm, yeah. This can be done in 2 nanoseconds by doing one index and one function, however I want mine to do it in 4 miliseconds. You may ask what it has? caching. It is sooo good it saves from 4 miliseconds into 3.8 miliseconds if you index something twice. It is a bad practice and just inneficient, but who cares?

I agree, I do not see how anyone would use my script either.

_G is much worse than simply localizing the services you need, with your method every service is given to the environments in which a service is used, this is inefficient on memory and indexing compared to importing only what you need. On top of that indexing _G is a lot slower than locals or globals.

Also worth noting that you’re using an __index function, these are generally discouraged in luaU due to the optimizations implemented with inline caching and metatables specifically, among having to call a function everytime, on top of your existing indexing. All of this In practice this makes it far, far less efficient than simply localizing services; there’s a point when abstractions go too far.