Tool animations playing despite tool not being equipped

  1. What do you want to achieve?
    When I unequip a tool, you should not be able to trigger animations specific to that tool anymore.

  2. What is the issue?
    The player can still trigger animations that should only play when you are holding the tool.

  1. What solutions have you tried so far?
    I have tried making it so that the player can only trigger animations when the weapon is parented to their character. For some reason that didn’t seem to work, so I think I did something wrong.
--Local script inside of tool. This part of the script sets the gun to the "lowered" position shown in the video.
script.Parent.Equipped:Connect(function()
	local M16 = player.Character:FindFirstChild("M16A3")
	if M16 then
		game:GetService("UserInputService").InputBegan:Connect(function(key)
			if key.KeyCode == Enum.KeyCode.Q then
				idleAnimTrack:Play()
				aimAnimTrack:Stop()
				idleAnimTrack.Looped = true
			end
		end)
	end
end)

Sorry if I screwed up on anything obvious, I’m still very new at scripting.

you can stop animations by using
tool.Unequipped:Connect(function()
sorry for typing it directly without code block. im on phone

1 Like

make it so when the tool unequips the tool ends all animations, so on the unequip event they stop all animations.

1 Like

There is already something like that in the script. It stops animations that are currently playing, but doesn’t stop them from being played again. Is this how I’m supposed to be doing things or am I far off?

script.Parent.Unequipped:Connect(function()
	equipAnimTrack:Stop()
	idleAnimTrack:Stop()
	aimAnimTrack:Stop()
end)
1 Like

Ignore that, that should work? However I could be wrong.

you can check it when key binded , example
if tool.Parent == Character then

3 Likes

This worked, thanks dude! I was worried.

1 Like

thats epic , good works with your game!