ServiceProvider

Show Deprecated
Not Creatable
Not Browsable

A ServiceProvider is an abstract class, which stores, and provides certain singleton classes, depending on what inherited class you are using its members with.

Summary

Properties

Events


Fires when the current place is exited.


Fired immediately after the ServiceProvider.Close signal is fired.


Fired when a service is created.


Fired when a service is about to be removed.

Methods

FindService(className: string): Instance  

Returns the service specified by the given className if it's already created, errors for an invalid name.

GetService(className: string): Instance  

Returns the service with the requested class name, creating it if it does not exist.

Properties

Events

Close

Fires when the current place is exited.


Code Samples

ServiceProvider.Close

1local function onClose()
2 print("The place is closing")
3end
4
5game.Close:Connect(onClose)

CloseLate

Local User Security

Fired immediately after the ServiceProvider.Close signal is fired.


ServiceAdded

Fired when a service is created.

Parameters

service: Instance

ServiceRemoving

Fired when a service is about to be removed.

Parameters

service: Instance

Methods

FindService

Returns the service specified by the given className if it's already created, errors for an invalid name.

Parameters

className: string

Returns

Code Samples

ServiceProvider:FindService

1print(game:FindService("Part"))
2--> nil
3
4print(game:FindService("Workspace"))
5--> Workspace

GetService

Returns a service with the class name requested. When called with the name of a service (such as Debris) it will return the instance of that service. If the service does not yet exist it will be created and the new service is returned. This is the only way to create some services, and can also be used for services that have unusual names, e.g. RunService's name is "Run Service".

Note:

  • This function will return nil if the className parameter is an existing class, but the class is not a service.
  • If you attempt to fetch a service that is present under another Object, an error will be thrown stating that the "singleton serviceName already exists".

Parameters

className: string

The class name of the requested service.


Returns

An instance of the requested service.

Code Samples

ServiceProvider:GetService

1local BadgeService = game:GetService("BadgeService")
2local GameSettings = UserSettings():GetService("UserGameSettings")
3
4print(BadgeService)
5print(GameSettings)