Gripping a gun...how to make characters use both hands to hold

Hello, I am making an assault rifle using tools but I do not know how to make it so the character will grip both hands on the gun.

Here is an example (not the model I’ll be using):
image

I was wondering if there was a special way to do this, like playing an animation until the player un-equips it and the animation will stop or something simpler that I was being dumb and didn’t see. Thanks in advance.

5 Likes

Well you could just create a simple animation where you hold the gun with both of your arms and then you could use the .Equipped event so that when you equip the tool then your animation will play, so for example:

Tool.Equipped:Connect(function()
         anim:Play()
end)

When you have unequipped the tool then the animation should be gone:


Tool.Unequipped:Connect(function()
         anim:Stop()
end)

Note: Also, make sure to add a loop to your animation so that it won’t work only once when you have equipped it

3 Likes

To add a loop do you just do “while true do” ?

and im guessing anim is just a variable for the animation

3 Likes

Nope, a loop to the animation else the animation will play and the Player still would only holds the gun with one hand. (In other words a looped animation with only 1 second as lenght)

1 Like

No, to loop an animation you don’t script it or anything, when you go on the animation editor there will be a button:

see that blue circle there? Yeah, thats the button if you want to loop animation.

Its the same as i say, or not?

You wasn’t that specific in terms of answering his question so I used a picture telling him thats the button that you need to press to loop the animation.

2 Likes

well, I tried to do that but I cant load the animation to the Humanoid because I cant reference it. I tried many different ways to do it none of them worked and I always got the same error:
OutPutError
Does anyone know what this means and how can I fix this and here is the code that I used

local tool = script.Parent
local Animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(tool.Animation)

 tool.Equipped:connect(function()
	Animation:Play()
end)

tool.Unequipped:connect(function()
	Animation:Stop()
end)

The local script probably didn’t get time to catch the character so your indexing nil, so I would use player.CharacterAdded:Wait() to wait for the character.

2 Likes

Best way to catch character in local script

local Player = Players.LocalPlayer
local PlayerCharacter = Player.Character or Player.CharacterAdded:Wait()

Alternatively, when you load the animation, you can set the Loaded property of the AnimationTrack (the object returned by LoadAnimation() and has the Play() function) to true in script.

local AnimationTrack = Animator:LoadAnimation(Animation) -- replacement of Humanoid:LoadAnimation() because it has been deprecated

AnimationTrack.Looped = true -- this makes the animation play in loop
AnimationTrack:Play()