Help with setting part rotation to bones!

Hello! Im making a snake game, and im using mesh deformation to do so, im using parts to guide the bones, and ive run into a problem!

The issue is that for some reason the bones just wont rotate right, i think its because roblox’s bones have properties that make it quite hard to line up with parts cframe, and this is causing issues.
This is what is should look like:
image
vs what it actually looks like once i try to implement rotation


as you can see it spazzes out, causing several issues

ive tried modifying the worldcframe, world rotation, ect. nothing seems to be working, my code is down below

local rootPart = snake.RootPart

local function getWorldOrientation(bone, offset)
	local defaultCFrame = rootPart.CFrame:Inverse() * bone.WorldCFrame

	local rotBase = rootPart.CFrame * CFrame.Angles(0, math.rad(offset), 0)
	local newRotationWorldSpace = (rotBase * defaultCFrame).Rotation

	local test = bone.Parent.WorldCFrame:Inverse()
	local destCFrame = (test*newRotationWorldSpace).Rotation + bone.CFrame.Position

	local rx, ry, rz = destCFrame:ToOrientation()
	local dx, dy, dz = math.deg(rx), math.deg(ry), math.deg(rz)
	return Vector3.new(dx, dy, dz)
end
local function movePartsAndBones()
	for i = 1, #baseParts do
		local basePart = baseParts[i]
		local bone = bones[i]
		local defaultCFrame = rootPart.CFrame:Inverse() * bone.WorldCFrame

		local offset = basePart.Rotation.Y

		bone.Orientation = getWorldOrientation(bone, offset)

		bone.WorldPosition = basePart.CFrame.Position
	end
end

im not asking for a full script, im simply asking for a function or some sort of formula that points me in the right direction, as im am extremely confused