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

How do I play the animation with KeyDown?

Asked by
JellyYn 70
6 years ago

I am trying to make it so when I press "e" on the keyboard, it plays an animation. I feel like the code should be right, but it says in the studio output: "Animation "https://www.roblox.com//asset/?id=https://www.roblox.com/library/963441784/Watch-Check-Animation&serverplaceid=0" failed to load in "Animation.AnimationId": Animation failed to load"

local mouse = game.Players.LocalPlayer:GetMouse()
local char = game.Players.LocalPlayer.Character
enabled = false

function KeyD(key)
    if enabled then
        enabled = false
        key = key:lower()
        if key == "e" then
            local emote = Instance.new("Animation")
            emote.AnimationId = "https://www.roblox.com/library/963441784/Watch-Check-Animation"
            local animloader = char.Humanoid:LoadAnimation(emote)
            animloader:Play()
        end
        enabled = true
    end
end

Thanks for the help. I guess.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

KeyDown is a depricated function a.k.a it can't be used anymore it only works in studio.

it is replaced for ther UserInputService

Do this:

plr = game.Players.LocalPlayer
chr = plr.Character

game:GetService('UserInputService').InputBegan:Connect(function(input, process)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.E and plr and chr then
            -- ur animation stuff
        end
    end
end)

also uhh try to make ur animation a child of the script like this (bcuz it may just be having no parent but the game itself)

local emote = Instance.new('Animation', script)

and also uhhhhhh say the AnimationId is this: "rbxassetid://(ur Idnumber)"

0
What scripters usually do is local uis = game:GetService("UserInputService") then do uis.InputBegan:Connect(function(input,process) end) instead of making a fat line of code saSlol2436 716 — 6y
0
Every scripter is different. Also, why make a variable if youre only going to use it once? hiimgoodpack 2009 — 6y
Ad

Answer this question