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

I need a piece of code that can help in an animation ?

Asked by 5 years ago

I need a piece of code that when u spam the key (In my case e) It only plays until it finishes.

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=03836741039"

mouse.KeyDown:connect(function(key)
    if key == "e" then
        local playAnim = humanoid:LoadAnimation(anim)
        playAnim:Play()
    end
end)
0
you could posibly wait the amount of time the animation takes AndriusTheGreat 140 — 5y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Check when the animation track isPlaying property is true

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=03836741039"
local UserInputService = game:GetService("UserInputService")
animationTrack = humanoid:LoadAnimation(anim)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then

        if(input.KeyCode == Enum.KeyCode.E)then
            if(not animationTrack.IsPlaying)then
                animationTrack:Play()
            end
        end
    end
end)

0
Thank you dinohunter8 2 — 5y
Ad

Answer this question