Giving an AI/Dummy a Tool

I was recently playing a game and noticed that the dummies all had tools, I attempted to recreate it by simply equipping the item to the dummies humanoid on the server and had negative results.

How could I give a dummy a tool and have it work exactly like it would on the client, activating it when needed, etc…

2 Likes

If you already have an AI script, all you would have to do is play the animation whenever the AI attacks.

You’d also need to put a tool in the AI’s inventory or weld it to the AI’s arm, and you could make it visible (and play an equipping animation if you choose to do so) whenever a player enters combat with it/ comes near it.

Now here’s some useful links (so I don’t get flagged):

The wiki says that the EquipTool() function only works for players, but in my experience it works with NPC humanoids too. So you could simply do this to get what you desire:

dummy.Humanoid:EquipTool(tool)
1 Like

I thought so as well, however using the following code I get no results, the tool simply doesn’t equip.

local Ai = script.Parent
local AiHumanoid = Ai:WaitForChild("Humanoid")

local Sword = game:GetService("ReplicatedStorage"):WaitForChild("Sword")

AiHumanoid:EquipTool(AiHumanoid)
1 Like

Try cloning the sword and parenting the clone to Workspace before trying to equip the tool.

  1. You need to set Sword to:
local Sword = game:GetService("ReplicatedStorage"):WaitForChild("Sword"):Clone() -- Note the "Clone" part. This is so that if there's multiple AIs the sword will still be there next time you try to equip it
  1. You’re attempting to equip the Humanoid… Change the equip line to this:
AiHumanoid:EquipTool(Sword)

Hope this helped!

2 Likes

I have made quite a few humanoid NPCs. I am pretty sure all you have to do is clone the sword from storage. Then parent the clone to the character model. This is exactly what happens when a real player equips a tool from their backpack. The tool is moved from the backpack to the character model.

Clearly the NPC can’t click the screen to activate the tool. This part would have to be simulated by the AI. At the proper moment you’d simply call the function that is run on a regular player’s tool.Activated event.

1 Like

This should be AiHumanoid:EquipTool(Sword)

2 Likes