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

How can i get my animation to stop when i let go of the key?

Asked by
liynux 0
4 years ago

Im trying to make a walking animation but instead of stopping when i let go of w it continues to play what can i add to fix this

local Player = game.Players.LocalPlayer
local Character = Player.Character or script.Parent
local Humanoid = Character.Humanoid
local UserInputService = game:GetService("UserInputService")
local AnimationId = 'rbxassetid://4397242217'
local Key = 'W'

UserInputService.InputBegan:Connect(function(Input, ItTyping)
    if ItTyping then return end
    if Input.KeyCode == Enum.KeyCode[Key] then
        local Animation = Instance.new("Animation")
        Animation.AnimationId = AnimationId
        local LoadAnimation = Humanoid:LoadAnimation(Animation)
        LoadAnimation:Play()
    Animation.Parent = Character
    Animation.Name = "Animation"
    end
end)

UserInputService.InputEnded:Connect(function(Input, IsTyping)
    if IsTyping then return end
        if Input.KeyCode == Enum.KeyCode[Key] then
        if Character:FindFirstChild("Animation") == true then
            Humanoid:LoadAnimation(Character:FindFirstChild("Animation")):Stop()
        end
    end
end)
0
line 24, :Stop() henry5266 5 — 4y
0
Hey there! When makings scripts and running them, be sure to open the Output tab. If you don't know where it is, then go to View > Output Sensei_Developer 298 — 4y

Answer this question