Animation Not Applying Correctly on Motor6D Weapon

I created a few animations for my custom tool-less weapon, but the animations are not being applied correctly.

Looking at the animations I made, it is smooth.

But when I tested it in game… The weapon clips into me! And the blocking animation doesn’t even play correctly!

I am stumped. I went to refer online through video tutorials, and they use the same Motor6D method and it works for them!

Motor6D Creation function. done on a server script that handles all the weapons

local function AttachWeapon(player, weaponName)
	local char = player.Character
	if not char then return end

	local rightArm = char:FindFirstChild("Right Arm")
	if not rightArm then return end

	local weaponTemplate = WeaponModels:FindFirstChild(weaponName)
	if not weaponTemplate then return end

	local currentModel = char:FindFirstChild("ActiveWeapon")
	if currentModel then currentModel:Destroy() end

	local newWeapon = weaponTemplate:Clone()
	newWeapon.Name = "ActiveWeapon"
	newWeapon.Parent = char

	local handle = newWeapon:FindFirstChild("Handle")
	if not handle then return end

	local CFrameValue = newWeapon:FindFirstChild("Value")
	if not CFrameValue then 
		warn("No CFrameValue found in " .. weaponName)
		return 
	end

	local motor = Instance.new("Motor6D")
	motor.Part0 = rightArm
	motor.Part1 = handle
	motor.C1 = CFrameValue.Value
	motor.Parent = rightArm

	char:SetAttribute("EquippedWeapon", weaponName)
end

Animation function, handled on the client in StarterPlayerScripts

local function LoadAnimation(name)
	if not CurrentWeaponData or not CurrentWeaponData.Animations[name] then return nil end
	if LoadedAnims[name] then return LoadedAnims[name] end

	local animObj = Instance.new("Animation")
	animObj.AnimationId = CurrentWeaponData.Animations[name]

	if not Animator then return nil end
	local track = Animator:LoadAnimation(animObj)

	if name == "Block" or name == "Idle" then
		track.Looped = true
	end

	LoadedAnims[name] = track
	return track
end

When the Animation is played

local function HandleAttack(inputState)
	if inputState ~= Enum.UserInputState.Begin then return end
	if not CurrentWeaponName then return end 
	if Character:GetAttribute("IsBlocking") then return end
	if not CanAttack then return end
	if IsDashing then return end 

	if CurrentWeaponData.WeaponType == "Ranged" then
		CanAttack = false
		
		local track = LoadAnimation("M1")
		if track then track:Play() end
		local mouse = Players.LocalPlayer:GetMouse()
		local targetPos = mouse.Hit.Position
		
		CombatRemote:FireServer("Fire", targetPos)
		task.wait(CurrentWeaponData.FireRate)
		CanAttack = true

	else
		CanAttack = false
		
		local track = LoadAnimation("M1")
		if track then track:Play() end
		
		CombatRemote:FireServer("M1")
		task.wait(CurrentWeaponData.AttackCooldown)
		CanAttack = true
	end
end

Note that

  • The Motor6D values I initalised in the scripts are exactly the same as the original Motor6D values I made when animating
  • AnimationPriority is set to Action

pls save me

Ideally you better cache cframe into upvalue and i think value is not the same

C0 is basically origin and C1 is essentially offset FROM origin.
You can compile CFrame value into code using Hierarchy-Saver

Incase value is dynamic you better off using attributes

i saved c1 as a cFrameValue, c0 is the same
the cFrameValue is correct, but the animation is wrong
cFrameValue

Motor6D of the original animation dummy

there’s no way i need to update the Motor6D C1 when the animation plays

Could be animation priority issue or fade in/out issue i guess.

I exported the animations with the animationpriority set to action :sob:

You can edit keyframe sequences directly, by the way, or even in AnimationTrack.
So what is left is fade in/out, I suppose.

Try :Play(0) this should prevent the fade-in effect and instantly play the animation.

By default the fade-time for animations is already 0.

Also this seems to be an animation priority issue, but not in the way you think. @DelightfulLele0707
It could be that, yes, the animation has the action priority, but I think your animations are overlapping eachother.

You should stop all other animations when say, an attack is playing. Make it so stuff like the idle animation don’t play, etc. This issue looks quite similar to how I have seen In my own game, when multiple animations were running. Quite odd.

1 Like

wow it was animations that were overlapping that caused the issue. thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.