How can i add custom animations to tools?

Hello! ive been working on a pistol script in my game and I think it would look better with some custom animations. I know how to make the animations but i dont know how to implement them into tools. Instead of the standard 1 hand holding animation i want to make a aiming idle animation. Ive tried replacing the weld connecting the hand and handle with a Motor6D but it didnt seem to work. I also want to override the startercharacters animate script animations with the tools own animation pack, but just replacing the animation values didnt work for me and bugged it out instead.

if anyone could give me an example or an answer that would be great.

Make sure you are making your own animation, and if you are working in a group game make sure the animation is saved within that group. After you’ve done that, I recommend this script.

local tool = script.Parent

tool.Activated:Connect(function()
	local humanoid = tool.Parent:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local AnimationId = Ad
		local Animation = Instance.new("Animation")
		Animation.AnimationId = "rbxassetid://" .. tostring(AnimationId)

		local AnimationTrack = humanoid:LoadAnimation(Animation)
		AnimationTrack:Play()
	end
end)

Remember, you cannot use any animations from toolbox. You need to make your own. This should work

You cant use :LoadAnimation on a humanoid since it isnt a method of a humanoid? You have to refrence the animator instead the humanoid instance.

I know how to load basic animations but not how to completely change the animation pack the character has. Like an idle or walking. And just replacing values from the default roblox animate script didnt work for me.

Edit: Nevermind you can use LoadAnimation but its deprecated and shouldn’t be used. LoadAnimation on an animator should be used instead.

You shouldn’t use LoadAnimation on every tool activation.

local tool = script.Parent
local character, humanoid, animator

local animation = script.Shot
local track = nil

local function singleLoadAnimationTrack()
  if character == tool Parent then return end
  character = tool:FindFirstAncestorWhichIsA("Model")
  humanoid = character and character:WaitForChild("Humanoid")
  animator = humanoid and humanoid:WaitForChild("Animator")
  track = animator:LoadAnimation(animation)
end

singleLoadAnimationTrack()
tool.Equipped:Connect(singleLoadAnimationTrack)

tool.Activated:Connect(function()
  if not animator then return end
  loadedTrack:Play()
end)