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

Setting an animation to a keybind?

Asked by
Razlio 0
8 years ago

Alright, so before I tell you my issue, i'm sort of new to scripting, so forgive me for being a noob to this.

What I was trying to do was test out a script to see if I can set an animation to a keybind. What I was trying to do is set a simple quick test animation I made to a keybind. It hasn't been working, unfortunately. This is the script I wrote. Thanks. How do I fix this?

`local animation = Instance.new("Animation")

animation.AnimationId = "http://www.roblox.com/sdGSDGDSGsdGdsGSDG-item?id=265122422"

local animController = Instance.new("AnimationController") local animTrack = animController:LoadAnimation(animation)

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key) if string.lower(key)== "x" then animTrack:Play() end end)

0
Put some of your script in a code block NotSoNorm 777 — 8y
0
^That means copy your script, click the Lua button, and paste between the lines. It's much easier to read that way. funyun 958 — 8y
0
I can answer I am an animation expert :P Hero_ic 502 — 8y

1 answer

Log in to vote
0
Answered by
Hero_ic 502 Moderation Voter
8 years ago

Hi there are a few problems that need to be fixed (like no code block lol) First what I like to do is make a variable for every animation

local animation --do not mess with this (this is for when we are playing animations)
local your_animation = Instance.new("Animation") --Change your to whatever you like
your_animation.AnimationId = "rbxassetid://265122422"

Next use userinputservice it functions way better

game:GetService("UserInputService").InputBegan:connect(function(KeyInput)
    if KeyInput.KeyCode == Enum.KeyCode.X --[[this is where you put your key where it says "X"]]  then 
        animation = player.Character.Humanoid:LoadAnimation(your_animation) -- loads animation
        animation:Play() --plays it
    end
end)

And that would be all that you need hope this helps! ~ KiHeros

Ad

Answer this question