I coded some fighting NPCs that currently only use a sword to fight each other. I want to add more weapons, but I’m having trouble with positioning the weapon properly when assigned. I tried moving the weapon model with :MoveTo() however that just made the weapon disappear, like you couldn’t find it in the explorer. I also tried just setting the position of one of the parts but instead of moving the weapon, it would move the fighter and the fighter would spawn tilted over sort of? I’m confused. Any help is appreciated, thanks!!
If you want to equip a tool to NPC, You can use Humanoid:EquipTool().
local NPC = --put your NPC here
local weapon = --put a weapon here
NPC.Humanoid:EquipTool(weapon)
If you want a random weapon, you can try this:
local WeaponList = { weapons here } --You can also put [Weapon Folder]:GetChildren() instead of list
local randomWeapon = WeaponList[math.random(1,#WeaponList)]
NPC.Humanoid:EquipTool(randomWeapon)
I parented the weapon’s contents to a tool instead of a model and used :EquipTool(). Works the same as the model for the most part, however I still need to be able to move the random weapon to the desired spot, as the NPCs will spawn in random positions. So same problem still persists.
Also, I forgot to mention I have a motor6D that’s attaches the weapon to the NPC, so :EquipTool(), which uses a weld to attach the tool, won’t work.
Oh I see, it’s because you need to set the grip of your tool. To easily do that, load up a rig in the studio, parent your tool inside that rig, move it to your desired spot, and then use the Apply Grip plugin to save the grip. After that, in game :EquipTool() should work perfectly fine!