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

Help Me With Adding Animations To Key Events?

Asked by
xTalzo 10
8 years ago

For example, I've been trying to do a flip by pressing the letter "e" I truly don't know how to do this.

1 answer

Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
8 years ago

All you have to do, using UserInputService, is to bind a certain key, to process and handle the animation.

local player = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local key = "E" -- key to bind

local animation = Instance.new("Animation")
animation.AnimationId = "animation asset id"
local character = player.Character or player.CharacterAdded:wait()

uis.InputBegan:connect(function(inputObject, processed)
    if not processed then
        if inputObject.KeyCode == Enum.KeyCode[key] then
            local humanoid = character.Humanoid

            if humanoid then
                local track = humanoid:LoadAnimation(animation)
                track:Play()
            end
        end
    end
end)

EDIT the second parameter to the InputBegan event, gameProcessedEvent, is a boolean value that is set to true if the game itself is processing the input... (ie: chatting).

0
Thanks you Soooo Much But it says " play is not a valid member of AnimationTrack" What Do I do? xTalzo 10 — 8y
0
right, it should be "Play".. instead of "play". ImageLabel 1541 — 8y
0
Thank you So Much! xTalzo 10 — 8y
Ad

Answer this question