How do I make a NPC (Non-player Character) hold out a Tool?

im trying to make an npc equip/unequip a tool and hold it out but I cant quite figure it out. im wanting to save welding and re-positioning the arm as a last resort.
when i equip a tool it goes on the npc’s right hand but the npc does not hold out the tool like how a player’s character would.

i wrote this but it doesnt work how I want it to:

local idle = "rbxassetid://507766388"
local toolnone = "rbxassetid://507768375"
local anim = Instance.new("Animation")
anim.AnimationId = idle


local LoadedAnim :AnimationTrack
local animNumber = 0
local function AnimLoop(NPC)
	animNumber += 1
	local CurrentAnim = animNumber
	while NPC do
		LoadedAnim = NPC.Humanoid:LoadAnimation(anim)
		-- i dont think loading the anim in the loop is the best idea
		LoadedAnim:Play()
		LoadedAnim.Stopped:Wait()
		if CurrentAnim ~= animNumber then
			break
		end
	end
end

this is how i run the function:

LoadedAnim:Stop()
anim.AnimationId = toolnone
task.spawn(AnimLoop, NPC)

the given code makes the npc hold out the tool but the npc becomes completely still because the toolnone animation does not have an idle animation. im wanting to somehow combine the both of these, preferably not like how this script does it. is there some sort of roblox function that does this for me that i dont know about?

2 Likes

You shouldn’t use Humanoid:LoadAnimation anymore, it’s deprecated. Instead, create a new instance inside the humanoid, they’re called Animators.

Next you’re gonna have to turn on the repeating animation button on the animation editor(the blue one)


Make sure that you update the animation after you do this

now just play the animation track once, and stop it when you want to:

local AnimationTrack = Humanoid.Animator:LoadAnimation(Animation)
AnimationTrack:play()

--when you want to stop
AnimationTrack:Stop()

thank you for this information about animators. would i have to make an entire animation just to have a npc’s arm be raised? it seems kind of insane to do that when normal characters do that automatically when you equip a gear.
also forgot to specify, this is a server script.

As far as i know, if Humanoid:EquipTool(Tool) doesn’t turn on the animation, then you should make your own and use the the example i sent you. Just a few frames of the character holding the tool should do.

Animating on the server isn’t a problem as long as the Character you’re animating isn’t a Player as far as i know.

I believe you can set the right shoulder motor’s desired angle to 90 degrees (half of pi).