Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to Add Specific Animation to Specific Tools? (Concepts)

How to Add Specific Animation to Specific Tools

How do I make it so when I have a tool like for example a sword in my hand and press a certain key like for example "z" it will play an animation and only if I have that specific tool in my hand.

My script plays the animation even if I don't have the tool in my hand.

Current Script- local keyPressed = Enum.KeyCode.C --Another example Enum.KeyCode.N local animationId = "11353437122" --Change to your animation Id local cooldown = 5 local debounce = false local tool = script.Parent

local userInputService = game:GetService("UserInputService") local player = game:GetService("Players").LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local animation = Instance.new("Animation") animation.AnimationId = "rbxassetid://"..animationId local animationTrack = humanoid:LoadAnimation(animation)

tool.Equipped:Connect(function() userInputService.InputBegan:Connect(function(input,isTyping) if isTyping then return end if input.KeyCode == keyPressed then if not animationTrack.IsPlaying then animationTrack:Play() if debounce then return end debounce = true else animationTrack:Stop() wait(cooldown) debounce = false end end end) end)

Send a message in "Help with tool"

1 answer

add local Connection = nil to the top and before userInputService.InputBegan:Connect() add

Tool.Equipped:Connect(function()
	Connection = userInputService.InputBegan:Connect(function()
		
	end)
end)
--then when unequipping
Tool.UnEquipped:Connect(function()
	if Connection then
		Connection:Disconnect()
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.