You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Well I’m making a tool to run custom animation.
What is the issue? I have a problem with nested instances like if i have “current_object.Part.Part.Part” and there’s a weld in the third part the code detect the weld but not the third part, code:
local StringToPath = function(String: string)
String = string.sub(String, 16)
local path = string.split(String, ".")
local currentInstance = animFolder.Parent.Parent
local directChild = currentInstance:FindFirstChild(path[1])
if directChild and #path == 1 then
return directChild
end
for i, name in ipairs(path) do
local nextInstance = currentInstance:FindFirstChild(name)
if nextInstance then
currentInstance = nextInstance
else
break
end
if i == #path then
local childCount = #currentInstance:GetChildren()
while childCount == 1 do
currentInstance = currentInstance:GetChildren()[1]
childCount = #currentInstance:GetChildren()
end
end
end
return currentInstance
end
What solutions have you tried so far? Not really anything.
What is this meant to do? The rest of your code alone would return the 3rd part, but this part of the code makes it so that if the 3rd part has 1 child then the code will return that child instead
Play = function(animFolder: Folder)
local t = game:GetService(“HttpService”):JSONDecode(animFolder.JSON_VALUE_INSTRUCTIONS.Value)
local StringToPath = function(String: string)
String = string.sub(String, 16)
local path = string.split(String, ".")
local currentInstance = animFolder.Parent.Parent
local directChild = currentInstance:FindFirstChild(path[1])
if directChild and #path == 1 then
return directChild
end
for i, name in ipairs(path) do
local nextInstance = currentInstance:FindFirstChild(name)
if nextInstance then
currentInstance = nextInstance
else
break
end
if i == #path then
local childCount = #currentInstance:GetChildren()
while childCount == 1 do
currentInstance = currentInstance:GetChildren()[1]
childCount = #currentInstance:GetChildren()
end
end
end
return currentInstance
end
local GetTime = function (Keyframe: {})
return Keyframe.time
end
local HandleAnimation = function (C_KeyFrame, tween: boolean)
for object_name: string, object: Instance in pairs(C_KeyFrame) do
if object_name ~= "time" then
for property_name, property in pairs(object) do
--Types Handling--
if property_name == "Color3" then
if not tween then
StringToPath(object_name).Color = Color3.new(unpack(property.Value))
else
print(StringToPath(object_name))
print(property_name)
print(unpack(property.Value))
print(GetTime(C_KeyFrame))
local d = game.TweenService:Create(StringToPath(object_name), TweenInfo.new(GetTime(C_KeyFrame)), {Color = Color3.new(unpack(property.Value))})
d:Play()
end
end
end
end
end
end
--Code--
for KeyframeIndex, CurrentKeyframe in pairs(t) do
local KeyFrameTime = GetTime(CurrentKeyframe)
if KeyframeIndex == 1 and KeyFrameTime ~= 0 then
HandleAnimation(CurrentKeyframe, true)
wait(KeyFrameTime)
elseif KeyframeIndex == 1 and KeyFrameTime == 0 then
HandleAnimation(CurrentKeyframe, false)
end
if KeyFrameTime == 0 and KeyframeIndex ~= 1 then
HandleAnimation(CurrentKeyframe, false)
end
local NextKeyFrame = t[KeyframeIndex+1]
if NextKeyFrame then
HandleAnimation(NextKeyFrame, true)
wait(GetTime(NextKeyFrame))
end
end
end
that’s the full function, i want like if object_name is like “current_object.Amrs.Left” I want it to get Left the instance.
Ok then everything you had except for what i quoted should work
Try this more simplified version of your code:
function StringToPath(String: string)
String = string.sub(String, 16)
local directory = string.split(String,'.')
local current = animFolder.Parent.Parent
for _,v in ipairs(directory) do
current = current:FindFirstChild(v)
if not current then break end
end
return current
end