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

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

Asked by
exarlus 72
5 years ago

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

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

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.

Ad

Answer this question