Putting a tool onto an NPC hands?

image

As you can see, I have my NPC, and the selection box is large because there is a weapon being put inside the model as well. What I am trying to achieve is the weapon being ‘equipped’ to the NPC’s hand. I can’t just position the weapon in workspace, then move it to RepStorage, as even tho that would clone to near the NPC, the NPC has an animation with their character, so they wouldn’t actually be holding the weapon.

Would any of the tools Properties be used to maybe like weld it to the NPCs arms. Specifically looking at the Grip ones. Basically need to have it welded to the arm, so it follows with the NPC’s animation.

EDIT This is all being done via the Client!! This is because the classes are only visible to the client, depending on which class they have selected in this menu! So it has to all be done via the client. I’ve tried doing it via the server and doing crazy deleting and repositioning to hide it from other players, but it’s just way to convaluted and didn’t end up working in the end.

So client only. Ik EquipTool does not work in the client, that’s why I’m trying to figure out how to manually equip a tool using the tools grips or something, idk :man_shrugging:

3 Likes

Heard of Moon Animation Suite plugin? You can make your tool and weld it to any part of the body you want. It has also animation categories. Search on YouTube Moon Animation Suite Tutorial. That should help.

4 Likes

Hmm ok. Only thing is that there are a number of different NPC’s that all run the same animation, but have different weapons. So I was hoping to use the tools GripPos to somehow weld it to the NPC’s arm (like how the normal player with the sword equipped would hold it)

EDIT Thought maybe using humanoid:EquipTool() would work with NPC humanoids, but that don’t seem to work :confused:

2 Likes
function loadIdleAnimation(humanoid)
	local animation = script['Idle']
if not animation then return end 

local animTrack = humanoid:LoadAnimation(animation)
	if not animTrack then return end

	animTrack.Looped = true
animTrack:Play()
end 

function getModel:Class(selected)
	local classFolder = classes:FindFirstChild(selected)
	if not classFolder then return end
	
	local armour = classFolder:FindFirstChild('Armour')
	if not armour then return end
	
	local weapon = classFolder:FindFirstChild('Weapon')
	if not weapon then return end
	
	local armourClone = armour:Clone()
	armourClone.Name = 'ArmourClone'
	
	local weaponClone = weapon:Clone()
	weaponClone.Name = 'WeaponClone'
	
	if workspace:FindFirstChild('ArmourClone') then
		workspace.ArmourClone:Destroy()
	end
	
	local character = armourClone
	local humanoid = character.Humanoid
	
	weaponClone.Parent = armourClone
	armourClone.Parent = workspace
	
	humanoid:EquipTool(weaponClone)
	
	loadIdleAnimation(humanoid)
end

Code if anyone wants to have a look. The weapon has to work with this preset animation

Maybe you need to play that animation AFTER it’s equipped by using humanoid:EquipTool(weaponClone).

1 Like

Even disabling the animation from playing at all, it doesn’t position it anywhere near the NPC :confused:

Try making new welds in the script using instance. Fist should be welded to the “Handle” of the weapon and make that weapon unanchored.

1 Like

RobloxScreenShot20190107_173242695
RobloxScreenShot20190107_173249704
Kinda works I guess

Not really sure how to get the rotations, etc. working :confused:

Maybe using the animations from within the weapon might help

EDIT Although, certain tools (like the sword) don’t use an Idle animation with their tool. They just use the players standard idle animation and the tools GripPos into the players hand :confused: So need to find a way for the sword (and any weapon that does not have an idle animation) to be gripped properly. Then weapons that do contains a preset idle animation (like the bow) can use their own idle animations?

1 Like

That would be easier to do with Moon Animation Suite. I mean you can place your tool however you want and animate with it, but you are trying to use script. Maybe you should make your animations inside the script and that script should be inside of tool? Not really sure.

Hmm :confused: Yea can’t really do that with the swords however :confused:

You could use a Motor6D, and set C1 to a CFrame constructed from the tool’s grip properties.

local Motor6D = Instance.new(”Motor6D”)
Motor6D.Part0 = Knight.LeftHand
Motor6D.Part1 = Tool.Handle
Motor6D.C1 = CFrame.new(Tool.GripPos, Tool:GripForward, Tool.GripRight, Tool.GripUp)

The reason this works is because the Grip properties are really just a CFrame split into it’s 4 parts.
p (GripPos),
lookVector (GripFront),
rightVector (GripRight), and
upVector (GripUp)

Let me know if this works!

local Motor6D = Instance.new('Motor6D')
	Motor6D.Part0 = armourClone.LeftHand
	Motor6D.Part1 = weaponClone.Handle
	Motor6D.C1 = CFrame.new(weaponClone.GripPos, weaponClone.GripForward, weaponClone.GripRight, weaponClone.GripUp)

Change it to accompnay my script, plus you also put Tool:GripForward, instead of Tool.GripForward. But here’s the error I get

[Invalid number of arguments: 4]

There is no valid constructor for CFrame with four vectors. You will have to use CFrame.new where you individually feed all 16 components of the vectors combined. See the CFrame page on the Developer Hub for an overview of which component goes where in the matrix:

Motor6D.C1 = CFrame.new(
	weaponClone.GripPos.x, weaponClone.GripPos.y, weaponClone.GripPos.z,
	weaponClone.GripRight.x, weaponClone.GripUp.x, -weaponClone.GripForward.x,
	weaponClone.GripRight.y, weaponClone.GripUp.y, -weaponClone.GripForward.y,
	weaponClone.GripRight.z, weaponClone.GripUp.z, -weaponClone.GripForward.z
)

Not sure if this is it? But it doesn’t work either way :confused:

1 Like

If you are still using regular ROBLOX Tool objects (with a handle in them), the Grip properties allow you to specify how the tool needs to be held. Specifically, Grip allows you to set how the tool is held with one positional and rotational CFrame.
This does require some trial and error if you can not immediately tell what is wrong with your grip.
Additionally, the most common issue with “NPC tools” is the fact that LocalScripts do not work inside NPCs. You may need to consider this, I do not know your current model structure.
You do not need manual welds nor animations for just holding stuff. Simply putting a Tool object with a BasePart named Handle inside a character will always make it start wielding the tool.
To make sure it is held the correct way, you can set the tool’s Grip before you parent it - either by creating a new Tool object and setting the Grip, or having a pre-made working Tool and simply reparenting/cloning it when it is needed.
Either way (in a Script or in your Command Line to do it in Studio), this is what you want to use:

tool.Grip = CFrame.new()

The supplied CFrame position and rotation will be used to weld the Handle to the hand.

Well I mean here’s a few problems with what I’ve tried so far and what you’ve listed:

  • Using like EquipTool() does not automatically equip it to the NPC character. I had to create a weld in a script to get it to actual appear even near the character (this did not equip the tool however)

  • The tools I’m using have preset Grip positions. So on a player they equip and look normal. It’s equipping with an NPC that ain’t working right

:EquipTool() seems to work for me on NPC humanoids.
Also is this code ran on the client? That may have an impact.

npchumanoids.rbxl (22.8 KB)

Same here, I can use EquipTool.

To add on to your Grip issue, you can always change the Grip after you put the Sword inside your NPC; or, in general, at all times in a Script.


Code

humanoid:EquipTool(weaponClone)	

@emojipasta as well

As the images show, ye it does put the tool inside the NPC, but it is being placed a million miles away. Can see in Explorer too that the NPC has all it’s normal parts + Humanoid.

1 Like

Is this code is ran on the client? That will have an impact if the server has network ownership over the character.

npchumanoidsclient.rbxl (22.8 KB)