✓ Accepted answer
This is actually pretty cool programming activity. The best way to do this would to be do some string manipulation. We basically treat every '.' as a divider between a parent and a child so we can get the name of something between each '.' and that will be the child we index from the parent we last indexed.
local path = "game.Workspace.Part.Position.X"
function proccessPath(s)
local currentParent = game
local startNum= string.find(s,'.',1,true)
local currentString = string.sub(s,startNum + 1)
local foundPeriod
local foundChild
repeat
foundPeriod = false
foundChild = false
local startNum = string.find(currentString,'.',1,true)
if startNum then
foundPeriod = true
elseif string.len(currentString) > 0 then
foundPeriod = false
startNum = 0
else
break
end
local childName = string.sub(currentString,1,startNum - 1)
currentString = string.sub(currentString,startNum + 1)
if typeof(currentParent) == "Instance" and currentParent:FindFirstChild(childName) or pcall(function() return currentParent[childName] end) then
foundChild = true
currentParent = currentParent[childName]
end
until not foundPeriod or not foundChild
if foundChild then
return currentParent
else
warn("Child or property could not be found :(")
end
end
print(proccessPath(path))
Outputs --> -6 Which was the position of the one part in my workspace at that time. The best thing about this is it works for properties too so you can do say "game.Workspace.Part.Position.X"
Well uh have fun with this function or whatever your gonna do with it. Cheers
1 comment
Use a for loop for every single part in the workspace and check if its the same or not