Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Setting an animation to a keybind?

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)

3 comments

0

Put some of your script in a code block

0

^That means copy your script, click the Lua button, and paste between the lines. It's much easier to read that way.

0

I can answer I am an animation expert :P

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.