How do I move limbs via CFrame during an Animation?

  1. What do you want to achieve? I want one of my rig’s limbs to track the player while in the midst of playing an animation for the rig. (E.g. Minigun hand that rotates minigunningly while tracking the player to mimic shooting at them)

  2. What is the issue? Include screenshots / videos if possible! !

Currnently the gun limb is being rotated via animation, and the tracking is (supposed to be) done by the CFraming

RobloxStudioBeta_sg1kppLsq6

or

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked around and found no proper solution. Doing both the CFrame process and animation at the same time breaks the rig.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

local MaxLookDistance = 1000
local MovementSpeed = 10

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local Debris = game:GetService("Debris")
local Spectator = script.Parent
local DefaultCFrame = Spectator.CFrame

local function getNearestPlayer()
	local part = nil
	local dist = MaxLookDistance
	for i,v in ipairs(Players:GetPlayers()) do
		local character = v.Character
		if character then
			local root = character:FindFirstChild("Head")
			if root then
				local thisDist = (root.Position-Spectator.Position).Magnitude
				if thisDist < dist then
					dist = thisDist
					part = root
				end
			end
		end
	end
	return part
end

local focusedPart = nil
local lastCheck = 0

RunService.Heartbeat:Connect(function(delta)
	if focusedPart then
		local cf = CFrame.lookAt(
			DefaultCFrame.Position,
			focusedPart.Position
		)
		Spectator.CFrame = Spectator.CFrame:Lerp(cf, delta * MovementSpeed)
	else
		Spectator.CFrame = Spectator.CFrame:Lerp(
			DefaultCFrame,
			delta * MovementSpeed
		)
	end
	if time() > lastCheck then
		lastCheck = time() + 1
		focusedPart = getNearestPlayer()
	end
end)

Spectator.Anchored = true