#Help improving this utility function

1 messages · Page 1 of 1 (latest)

stiff beacon
#

local function getObjectFromPath(path, root) root = root or game local currentChild = root for depth, childName in pairs(string.split(path, "/")) do currentChild = currentChild:FindFirstChild(childName) if not currentChild then break end end return currentChild end

Takes paths in the format "Workspace/SomeFolder/SomeModel/SomePart" and tries to go down the hierarchy, starting at root (game by default). I don't think this is as elegant as it could be. Any suggestions?

wild ridge
#

not sure whats the exact need of this since there is already "FindFirstChild(name:string,recursive:boolean)" which accesses descendants too if recursive parameter is set, but your function do get the job done

#

i dont think it could get simpler