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

How to make animation stop when one key stops being pressed?

Asked by
exarlus 72
5 years ago

So basically in this script you have to press 2 keys to run a certain animation "W and A". However pressing W runs another animation(in another script) so whenever a player stops holding down A the animation for pressing "W and A" still plays instead of going back to the animation when W is being held down.

Script:

local p = game.Players.LocalPlayer
local anim = script.Animation
local serv = game:GetService("UserInputService")
local keyCodeW = Enum.KeyCode.W
local keyCodeA = Enum.KeyCode.A
local char = p.Character 
if not p.Character then 
    repeat wait() until p.Character 
end
local human = char:WaitForChild("Humanoid") 
wait(1)
local newAnim = human:LoadAnimation(anim)
serv.InputBegan:Connect(function(key,processed)
     if serv:IsKeyDown(keyCodeW) and serv:IsKeyDown(keyCodeA) then 
        print("Starting animation!")
        newAnim:Play()
    end
end)


serv.InputEnded:Connect(function(key,processed)
    if not serv:IsKeyDown(keyCodeW) then
        newAnim:Stop()
    end
end)
1
It would be best not to split up the animations and put them all in the same script. User#5423 17 — 5y
0
they should be in separate scripts for obvious reasons DeceptiveCaster 3761 — 5y
0
they are in separate scripts.Its just that theres animations for pressing A and W. W is for moving foward and A is for moving left... so when you wanna move Foward and left you have to press W and A however when a player stops holding down A it continues playing the animation for W and A instead of going back to the animation that plays when you click W. exarlus 72 — 5y

Answer this question