Animation Not Playing When Key is Clicked

28 views Asked by At

The animation is not playing on the player when F is clicked. The script is a local script and is inside StarterCharecterScripts. Here is the code:

local inputservice = game:GetService("UserInputService")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://15668747099"
local isplaying = false
local keycode = Enum.KeyCode.F
local plr = game.Players.LocalPlayer
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local animplay = humanoid:LoadAnimation(animation)

inputservice.InputBegan:Connect(function(key)
    if key.KeyCode == keycode then
        if isplaying == false then
            isplaying = true
            animplay:Play()
            animplay.Stopped:Connect(function()
                isplaying = false
            end)
        end
    end
end)

I have tried many things but they haven't worked.

Any help would be appreciated!

0

There are 0 answers