GetService
GetService is a function used in Roblox Lua to obtain a reference to a core service within a game's data model. It is called on the root object game with the service name provided as a string, for example: local players = game:GetService("Players"). The method returns the singleton instance of the requested service.
GetService ensures that the requested service is loaded and available before returning it. If the service is
Common usage includes retrieving widely used services such as Players, DataStoreService, RunService, ReplicatedStorage, and Lighting. Using
local players = game:GetService("Players")
local runService = game:GetService("RunService")
- The argument must be the exact service name as a string; invalid names cause runtime errors.
- GetService is recommended for engine-provided services to ensure they are ready before use. For modules and
In summary, GetService is a standard, robust way to access Roblox services by name, ensuring a valid,