local function V(V)if V.Magnitude==0 then return Vector3.zero end return V.Unit end return function(K,s,P)do end local g=K.ParentIndex local o=P.Bones[g]if not o then do end return s end local p=o.RotationLimit if p>=180 then do end return s end local I=P.Bones[o.ParentIndex]if not I then do end return s end local y=o.Position local e=V(o.Position-I.Position)local S=(s-y).Magnitude local t=V(s-y)if p<=0 then do end return y+e*S end local f=math.rad(K.RotationLimit)local N=math.acos(e:Dot(t))local W if N>=f then local K=V(e:Cross(t))W=CFrame.fromAxisAngle(K,f)*e else W=t end s=y+W*S do end return s end
local function SafeUnit(v3)
	if v3.Magnitude == 0 then
		return Vector3.zero
	end

	return v3.Unit
end

return function(self, Position, BoneTree)
do end	
local ParentIndex = self.ParentIndex
	local ParentBone = BoneTree.Bones[ParentIndex]

	if not ParentBone then
do end		
return Position
	end

	local ParentBoneLimit = ParentBone.RotationLimit

	if ParentBoneLimit >= 180 then
do end		
return Position
	end

	local GrandParentBone = BoneTree.Bones[ParentBone.ParentIndex]

	if not GrandParentBone then
do end		
return Position
	end

	local ParentBonePosition = ParentBone.Position
	local DefaultDirection = SafeUnit(ParentBone.Position - GrandParentBone.Position)

	local DistanceToParent = (Position - ParentBonePosition).Magnitude
	local DirectionToSelf = SafeUnit(Position - ParentBonePosition)

	if ParentBoneLimit <= 0 then
do end		
return ParentBonePosition + DefaultDirection * DistanceToParent
	end

	local RotationLimit = math.rad(self.RotationLimit)
	local VectorAngle = math.acos(DefaultDirection:Dot(DirectionToSelf))
	local LimitedVector

	if VectorAngle >= RotationLimit then
		local Cross = SafeUnit(DefaultDirection:Cross(DirectionToSelf))
		LimitedVector = CFrame.fromAxisAngle(Cross, RotationLimit) * DefaultDirection
	else
		LimitedVector = DirectionToSelf
	end

	Position = ParentBonePosition + LimitedVector * DistanceToParent
do end	

return Position
end
