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

PAYING | Roblox Studio | Stop repeating animation when key is off press?

Asked by 6 years ago
local animations = {
                --Add your animations here like this format
                [Enum.KeyCode.W] = 1288223958,--Plays when "K" is pressed

    }



repeat wait() until game.Players.LocalPlayer; local player = game.Players.LocalPlayer
repeat wait() until player.Character; local character = player.Character
local currentAnimId,currentPlaying = '',nil
local humanoid = character:FindFirstChild('Humanoid')
local uis = game:GetService('UserInputService')

uis.InputBegan:connect(function(input,gpe)
    if not gpe then
        if animations[input.KeyCode] ~= nil then
            local animId = 'http://www.roblox.com/Asset?ID=' .. animations[input.KeyCode]
            if animId ~= currentAnimId then
                if humanoid ~= nil and humanoid.Health > 0 then
                    if currentPlaying ~= nil and currentPlaying.IsPlaying then
                        currentPlaying:Stop()
                    end
                    local animation = Instance.new('Animation'); animation.AnimationId = animId
                    local animTrack = humanoid:LoadAnimation(animation); currentPlaying = animTrack
                    animTrack:Play(0.100000001,1,1)
                end
            end
        end
    end
end)

So that's my script, it's a walking animation, but it carries on the animation even when i stop pressing "W". This is supposed to be easy? Please help me out,

Thank you, Aquascent.

0
Have you read the rules? :) BoomerBoxer 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

http://wiki.roblox.com/index.php?title=API:Class/UserInputService/IsKeyDown

http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Running

Ad

Answer this question