ServiceProvider

Pokaż przestarzałe

*Ta zawartość będzie dostępna wkrótce w wybranym przez ciebie języku.

Brak możliwości tworzenia
Brak możliwości przeglądania

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

Podsumowanie

Metody

  • Zapis równoległy

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

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

Zdarzenia

Właściwości

Metody

FindService

Zapis równoległy

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

Parametry

className: string

Zwroty

Przykłady kodu

ServiceProvider:FindService

print(game:FindService("Part"))
--> nil
print(game:FindService("Workspace"))
--> 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".

Parametry

className: string

The class name of the requested service.


Zwroty

An instance of the requested service.

Przykłady kodu

ServiceProvider:GetService

local BadgeService = game:GetService("BadgeService")
local GameSettings = UserSettings():GetService("UserGameSettings")
print(BadgeService)
print(GameSettings)

Zdarzenia

Close

Fires when the current place is exited.


Przykłady kodu

ServiceProvider.Close

local function onClose()
print("The place is closing")
end
game.Close:Connect(onClose)

ServiceAdded

Fired when a service is created.

Parametry

service: Instance

ServiceRemoving

Fired when a service is about to be removed.

Parametry

service: Instance