Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

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)
Ad

Answer this question