Allow us to create custom services

As a Roblox developer, it is currently too hard to make custom services for my game, I can use modules, but the path can be very messy like this: Baseplate.Workspace.Place.plays.visits.names.module and it’s more difficult to get it, and there’s limitation with the module like not being able to send requests to roblox.com unless you use a proxy (I can use public proxies but there are issues with it, and making my own one requires some node.js skills and I don’t even know how to make one) and getting the user’s age (It’s possible through PolicyService but it only have the social media items the user can see, check if they can see ads and more), and sure, _G can help with the messy folders, but it has more problems such as non-accessibility on server and client, no type checking unless you use table brackets, when you add a . after _G, nothing appears, literally nothing

If Roblox is able to address this issue, it would improve my development experience because I will be easily able to create custom services, without having to worry about the problems I’m facing with modules and _G, and use certain items only available in CoreScripts in case I need to get the player’s age, sending requests to roblox.com and more…

1 Like

Wow! It’s almost like you’re not supposed to send requests to roblox.com at all, least of all to try to get players’ personal information. :slight_smile:

You’re not meant to use _G, global scope is messy and prone to initialization flow problems. You can work around the module path issue by using a proxy module to require from a collection of libraries directly under replicated storage. Helps a lot if the rest of your architecture isn’t a mess.

image

local modules = {}
for _,module in ipairs(script:GetChildren()) do
	if module:IsA("ModuleScript") then
		modules[module.Name] = module
	end
end


local function requireModule(name)
	return require(modules[name])
end

return {require = requireModule}
local RS = game:GetService("ReplicatedStorage")
local modules = require(RS:WaitForChild("Modules"))
local theModule = modules.require("TheModule")

Above also works if you just pass the module lookup straight through instead of using a table in the middle. You can also organize within subfolders that the getter module abstracts away if you really feel like overengineering this.

12 Likes

and I know i’m not meant to use _G, I never used it in any of my code, also it only gets it by a name, so if I have 2 modules named “Module” and 5 modules named “MainModule” it will only get one of these modules, which is the issue in your idea

Don’t name them that way, seems pretty common sense.

3 Likes

I know, but when you add a dot, nothing comes in, same like putting numbers in require(), and there are limitations like not being able to request roblox.com unless you use a proxy, and getting the game’s likes, visits, and current players, showing how many people earned a badge, how many sales an item have, etc.

Not being able to access roblox.com is intentional, and being able to define a custom service won’t let you access it. It’s a security feature that Roblox puts on developers
¯\_(ツ)_/¯

1 Like

i mean when you make a custom service, you can request roblox.com and if it’s intentional, then how do I get the game’s likes, visits, player count? how do I get item sales? and how do I show how many people earned a badge?

1 Like

What do you mean “when you make a custom service”? Developers can’t create services, allowing us to create services won’t give us the ability to access roblox.com.

I feel you aren’t reading replies fully.

Roblox does not want us to be able to access roblox.com to stop developers doing bad things.

If you want to be able to get the number of people who have earned a badge without using a proxy, then now is the time for a feature request to allow direct access to Roblox’s HTTP API.

1 Like

i mean when someone creates a custom service (if implemented), and I know, and they might do it, and if roblox doesn’t want us to do it, then how do I get the game’s likes, visits, player count? how do I get item sales? and how do I show how many people earned a badge?

1 Like

That is something you should ask Roblox.

If your game needs to be able to get this information, you have the power to make a feature request to allow direct access to Roblox’s web API instead of having to use a proxy.

Asking for a way to require scripts through :GetService is not the way to get there.

that’s a highly-requested feature, and how do I have the power? I’m not a regular at all, the roblox staff approved it and created it here

also it should be done using :GetService() and it will be a way and I can’t use modules for problems I listed above

There could be a feature request for autocomplete to work correctly in that scenario.

This thing kind of applies to services? Just don’t name modules the same thing. This issue could still happen with custom services if you name them the same thing lol.

That’s more of an organizational problem with how you make your games and structure your code.

Clearly whatever method you are using to create feature requests is working, as far as I can tell you can make another one requesting a feature if you wanted.

Also, services in Roblox are their own instance types and therefore are programmed in C++. Developers can’t define custom instance types, and :GetService searches for objects using the instance type, not the actual name. For example, UserInputService actually used to be named Instance, making it impossible to use it without using :GetService (now you can use it through game.UserInputService).

(Also, look for older feature requests before you try to create a new one. If you have found a feature request for API access, reply to it instead of making a new one.)

Once upon a time I would’ve agreed, but nowadays I don’t think it’s good for developers to be allowed to create custom services. Yes to custom objects but not services. You don’t need to and shouldn’t need to create your own services, nevermind the practice problems that can arise out of them.

Building your own structure for your experience that contains your own services (using, for example, the concept of MVC as your base) is much more valuable since you get direct control over - as the first post says - initialisation control, maintainability and so much more. You can even use existing ones if you think that building your own is too difficult, such as Knit (be mindful of its creators’ own thoughts on it: Knit, it’s history and how to build it better).

I personally use Knit as-is – though in a way not necessarily intended (by making everything get called by Knit instead of having some free structure as well), it’s more than resolved the “use cases” I would’ve had in asking for custom service creation long ago. I wouldn’t even say anymore that creating your own services out of convenience is a good thing.

Aim for reusability and versatility in your own codebase first. You start changing your views on things like use cases and potential feature requests when you start seriously working on a project and see just how much you can do without certain things being available.

1 Like

I will not say my opinion on this topic, But this removes the types for the module.

1 Like

ok, I need this topic closed, as I don’t need custom services, like what @colbert2677 said

(but I might make a module for that, hya123456h made one but it uses _G which is bad practice)