Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Releasing the keys stops the animation but if I hold the keys for a while the animation continues?

the title explains it all.

if you hold the keys for a while after releasing the keys the animation loops itself even after the keys aren't being held anymore.

Script:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local UIS = game:GetService'UserInputService'
local keyCodeQ = Enum.KeyCode.Q
local keyCode_E = Enum.KeyCode.E

UIS.InputBegan:Connect(function(input, chatting)
    if chatting then
        return
    end

    if UIS:IsKeyDown(keyCodeQ) and UIS:IsKeyDown(keyCode_E) then
         local Anim = Instance.new('Animation')
  Anim.AnimationId = 'rbxassetid://2007811727'
  PlayAnim = Character.Humanoid:LoadAnimation(Anim)
  PlayAnim:Play()
    end
end)

UIS.InputEnded:Connect(function(input, chatting)
    if chatting then
        return 
    end

    if not UIS:IsKeyDown(keyCodeQ) and not UIS:IsKeyDown(keyCode_E) then
        PlayAnim:Stop()
    end 
end)

1 answer

✓ Accepted answer

There is a function called InputEnded and you can use it similar to InputBegan. Inside the InputEnded function you can tell your script to stop.

This discussion is preserved as it was. New answers, comments, and votes are closed.