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)
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