Key down animation script isn't working


#1

Hey developers I have a question about a key down animation script. The animation is a front flip. I am trying to make it so when a player presses “r” on his or her keyboard it does the animation. I looked it up on You Tube and the script that is given in the video doesn’t work. I don’t know if it would effect anything that the game is saved to my desktop. Let me know a new way or how to fix it thanks! From John…

Animation link: https://www.roblox.com/library/2074693420/Front-Flip


#2

Replace line 7 with this

anim.AnimationId = "rbxassetid://2074693420"

#3

Ok thanks!


#4

You can also try other methods to achieve such goals by using services such as UserInputService and ContextActionService.


ContextActionService

This service is slightly faster since it will fire only when the button you want is pressed, unlike UserInputService where it will check every input until it finds the input from the key that’s desired.

local CAS = game:GetService("ContextActionService")
local deb = false

local function Binding(name, state, obj)
    if not deb then
       if state == Enum.UserInputState.Begin then
          deb = true
          --Action
         deb = false
       end
    end
end

CAS:BindAction("AnimationPlay (change this to anything)", Binding, false, Enum.KeyCode.R)

UserInputService

local UIS = game:GetService("UserInputService")

local function InputBegan(input, processed)
    if input == Enum.UserInputType.Keyboard then
       local key = input.KeyCode
       if key == "R" then
          --Action
       end
    end
end

UIS.InputBegan:Connect(InputBegan)

Only one key plays