Created
October 16, 2022 21:49
-
-
Save howmanysmall/48fda51b347347601e842ff953856305 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function GetService(ServiceName: string) | |
return game:GetService(ServiceName) | |
end | |
local ServicesMetatable = {} | |
function ServicesMetatable:__index(Index) | |
local Success, Object = pcall(GetService, Index) | |
local Service = Success and Object | |
self[Index] = Service | |
return Service | |
end | |
local Services = setmetatable({}, ServicesMetatable) | |
local Metatable = {} | |
function Metatable:__index(Path: string): Instance? | |
local CurrentObject = nil | |
for Index, PathValue in string.split(Path, ".") do | |
if Index == 1 then | |
local Service = Services[PathValue] | |
if not Service then | |
self[Path] = nil | |
return nil | |
end | |
CurrentObject = Service | |
else | |
if CurrentObject then | |
local Object = CurrentObject:FindFirstChild(PathValue) | |
if Object then | |
CurrentObject = Object | |
end | |
end | |
end | |
end | |
self[Path] = CurrentObject | |
return CurrentObject | |
end | |
function Metatable:__call(Path: string): Instance? | |
return self[Path] | |
end | |
local GetObjectFromPath = setmetatable({}, Metatable) | |
return GetObjectFromPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment