Created
May 11, 2021 18:38
-
-
Save howmanysmall/f0122c25e28446333563d770ecd08a34 to your computer and use it in GitHub Desktop.
replaces `getfenv(2).script` or whatever
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 GetObjectFromPathMetatable = {} | |
function GetObjectFromPathMetatable:__index(Path: string) | |
local CurrentObject = nil | |
for Index, PathValue in ipairs(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 GetObjectFromPathMetatable:__call(Path: string) | |
return self[Path] | |
end | |
local GetObjectFromPath = setmetatable({}, GetObjectFromPathMetatable) | |
print(GetObjectFromPath(debug.info(2, "s"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment