How do I get every part in a rig that is animatable?

As I am currently making my own custom animator I need to be able to get every part in a rig that can be animated(Attached with motor6Ds and what not)

I found this tutorial with code that well in theory loops through all the parts in the rig and if they are attached to a motor then it’d return it, but all it returns is the root and torso, why is this?

local function getAnimatables(model)
	if not model.PrimaryPart then
		warn("No primary part set")
		return
	end

	local rootPart = model.PrimaryPart:GetRootPart()

	if not rootPart then
		warn("Root part not found")
		return
	end

	local partsAdded = {}
	partsAdded[rootPart] = true

	local function addPoses(part)
		-- get all of the joints attached to the part
		for _, joint in pairs(part:GetJoints()) do
			-- we're only interested in Motor6Ds
			if joint:IsA("Motor6D") then
				-- find the connected part
				local connectedPart = nil
				if joint.Part0 == part then
					connectedPart = joint.Part1
				elseif joint.Part1 == part then
					connectedPart = joint.Part0
				end
				if connectedPart then
					-- make sure we haven't already added this part
					if not partsAdded[connectedPart] then
						partsAdded[connectedPart] = true
						
					end
				end
			end
		end
	end

	addPoses(rootPart)

	return partsAdded
end

I can see that it gets all the joints in a part and what not but like yeah no clue tbh

2 Likes

This is just overcomplicating something extremely simple.

for i, v in pairs(model:GetChildren()) do
if v:IsA("Motor6D") then
print(v)
end
end
1 Like

This code gives you every motor 6D. . . not get every part that is animatable, meaning its connected to so called motor 6d

1 Like

I believe the function only finds item connected to the root. Try doing this, not tested so idk if it will work:

local function getAnimatables(model)
	if not model.PrimaryPart then
		warn("No primary part set")
		return
	end

	local rootPart = model.PrimaryPart:GetRootPart()

	if not rootPart then
		warn("Root part not found")
		return
	end

	local partsAdded = {}
	partsAdded[rootPart] = true

	local function addPoses(part)
		-- get all of the joints attached to the part
		for _, joint in pairs(part:GetJoints()) do
			-- we're only interested in Motor6Ds
			if joint:IsA("Motor6D") then
				-- find the connected part
				local connectedPart = nil
				if joint.Part0 == part then
					connectedPart = joint.Part1
				elseif joint.Part1 == part then
					connectedPart = joint.Part0
				end
				if connectedPart then
					-- make sure we haven't already added this part
					if not partsAdded[connectedPart] then
						partsAdded[connectedPart] = true
						addPoses(connectedPart)
					end
				end
			end
		end
	end

	addPoses(rootPart)

	return partsAdded
end
1 Like

Ok so this is still giving me just the torso and root, I modified the code a little but nothing that would break it! Im so confused!

local function getAnimatables(model)
	if not model.PrimaryPart then
		warn("No primary part set")
		return
	end

	local rootPart = model.PrimaryPart:GetRootPart()

	if not rootPart then
		warn("Root part not found")
		return
	end

	local partsAdded = {}
	partsAdded[rootPart.Name] = rootPart

	local function addPoses(part)
		-- get all of the joints attached to the part
		for _, joint in pairs(part:GetJoints()) do
			-- we're only interested in Motor6Ds
			if joint:IsA("Motor6D") then
				-- find the connected part
				local connectedPart = nil
				if joint.Part0 == part then
					connectedPart = joint.Part1
				elseif joint.Part1 == part then
					connectedPart = joint.Part0
				end
				if connectedPart then
					-- make sure we haven't already added this part
					if not partsAdded[connectedPart] then
						partsAdded[connectedPart.Name] = connectedPart
					end
				end
			end
		end
	end

	addPoses(rootPart)

	return partsAdded
end
1 Like

you never add the pose of the connected part… You have to call the addpose again…

local function getAnimatables(model)
	if not model.PrimaryPart then
		warn("No primary part set")
		return
	end

	local rootPart = model.PrimaryPart:GetRootPart()

	if not rootPart then
		warn("Root part not found")
		return
	end

	local partsAdded = {}
	partsAdded[rootPart.Name] = rootPart

	local function addPoses(part)
		-- get all of the joints attached to the part
		for _, joint in pairs(part:GetJoints()) do
			-- we're only interested in Motor6Ds
			if joint:IsA("Motor6D") then
				-- find the connected part
				local connectedPart = nil
				if joint.Part0 == part then
					connectedPart = joint.Part1
				elseif joint.Part1 == part then
					connectedPart = joint.Part0
				end
				if connectedPart then
					-- make sure we haven't already added this part
					if not partsAdded[connectedPart] then
						partsAdded[connectedPart.Name] = connectedPart
						addPoses(connectedPart)
					end
				end
			end
		end
	end

	addPoses(rootPart)

	return partsAdded
end
1 Like

Addposes recalls the function though, although yes it works but then this happens:

▶ Script 'user_Animate.rbxmx.Animate.Control', Line 98 - function addPoses (x4996)```
it gets used 5K times which lags out everything so that wont work
1 Like

Can you print out connectedPart? Also what does the rig look like? Also can I see where you use GetAnimatables?

really simple to get all animated parts

local AddedParts = {}
for _, i in pairs(Rig:GetChildren()) do
	if i:FindFirstChildOfClass("Motor6D") then
		for a, v in pairs(i:GetChildren()) do
			if v:IsA("Motor6D") then
				if table.find(AddedParts, v.Part1) == nil then
					table.insert(AddedParts, v.Part1)
				end
			end
		end
	end
end

That would not work because it does not include the possibility of having disconnected Motor6D’s or flipped Motor6D’s. However, a modified version of this code would work significantly better than what he had, I was just too lazy to try to explain what I would write.

i’ve tried making an animation plugin before an i think i had a system for flipped motor6ds.

It only prints torso

The default R6 man rig

local function Display(rigs)
	-- display rigs and there animtable objects
	
	local Animatables = {}
	local motors = {}
	
	for _, rig:Model in pairs(rigs) do -- get animatable objects
		local rigData = {
			Animatables = {},
			Anim = nil
		}
		
		local parts = getAnimatables(rig)
		
		for name, part in pairs(parts) do
			print(name,part)
		end
		-- get all parts and see if they are attached in any way.
		
	end
end