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

How to animate tool on hotkey?

Asked by 7 years ago

I need help on scripting my tool. So I want my tool to animate when i press a hotkey since I wanted to have a various animations on my tool.

0
This isn't a requesting forum, please try before you post or goto wiki.roblox.com for help User#10445 15 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

First of all, you're going to create a function which fires when you press a hotkey.

local keyToPress = "e" -- This is the hotkey.

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key))
    if string.lower(key) == keyToPress then
        print("You just pressed the E hotkey!")
    end
end

Now we're going to make that function play an animation using this.

local keyToPress = "e" -- This is the hotkey.
local animation = script.Animation -- You're gonna have to edit that.
animTrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation)

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key))
    if string.lower(key) == keyToPress then
        animTrack:play()
    end
end
Ad

Answer this question