GetService
Looks up a Roblox service by type name. The only generic besides collections and static_cast.
Syntax
Section titled “Syntax”T GetService<T>();Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
T | class name | Service class, e.g. Players, RunService. |
Return value
Section titled “Return value”An Instance of class T (game:GetService("T")).
Luau emit
Section titled “Luau emit”game:GetService("T")
Description
Section titled “Description”T is the Roblox class name, not a C++ template you define. You must #include <clpp/roblox.clh> (IntelliSense) so the editor knows the type.
There is no game:GetService in CL++ source — always this form.
Example
Section titled “Example”#include <clpp/roblox.clh>
void init() { Players players = GetService<Players>(); post("online: " .: players.GetPlayers());}Emits:
local players: Players = game:GetService("Players")print("online: " .. players:GetPlayers())