Help with this bone scale code

The bug in the original script was that ‘bone.Parent.CFrame’ was being treated as if in world space, but this is not the case for parent Bones where we need to use bone.Parent.WorldCFrame.

The other changes are just variable renaming, and extra variables to try to make the script easier to understand.

Thank you so much for your reply and the fix to the script.
I really appreciate code snippets because it really helps me learn.
So thanks again.

Also, just a fyi, the ‘BuildTree’ function in my code was a local function defined inside of the ScaleMesh function (for recursive traversal of the bone structure)

	local function BuildTree(tree,mesh,inst,scale)
		if inst:IsA("Bone") or inst:IsA("Attachment") then
			local cf = mesh.CFrame:ToObjectSpace(inst.WorldCFrame)
			cf = mesh.CFrame:ToWorldSpace((cf - cf.Position) + (cf.Position * scale))
			table.insert(tree,{Pos = cf.Position,Inst = inst})		
		end
		for _,i in pairs(inst:GetChildren()) do
			BuildTree(tree,mesh,i,scale)
		end
	end
1 Like