local kicking = Instance.new("Animation") kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670" mouse = game.Players.LocalPlayer:GetMouse() function keyDown(key) key = key:lower() if key == 't' then local animTrack = Humanoid:LoadAnimation(kicking) animTrack:Play() end end mouse.KeyDown:connect(keyDown)
For some reason it's not working, and it's not telling me what's wrong.
This line
kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670"
is your problem. AnimationId has to be an "asset," but you copied the "item" link.
Solution: replace that line with this:
kicking.AnimationId = "rbxassetid://273619670"
What's Humanoid
? Assuming that this is the whole script, you should see a blue underline underneath Humanoid
, which means that it's an undefined term. So, what you should do is define it.
-- ALSO NOTE THAT I'M ASSUMING THIS SCRIPT IS A LOCAL SCRIPT. If this isn't one, then switch to it! local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:WaitForChild("Humanoid") -- Humanoid is now defined! local Mouse = Player:GetMouse() local kicking = Instance.new("Animation", Humanoid) -- EDIT: I've parented the animation object inside the Humanoid. kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670" local function keyDown(key) key = key:lower() if key == 't' then local animTrack = Humanoid:LoadAnimation(kicking) animTrack:Play() end end --[[ Note the tabs. This is for organization purposes and will lower the chance of making any "eof" errors. --]] Mouse.KeyDown:connect(keyDown)
That should work.
Although I should note that in here, the KeyDown event is deprecated and should not be used in the future. It's there for compatibility purposes with the older tools.
What you should use for input is UserInputService. This gives you more input mediums such as cell phone devices or Xbox 360 controllers.
Also, I noticed that there's no trace of implementation of a debounce or a wait() function. You should implement them, because they allow a more realistic output for your case. You don't want your character to start to kick if it haven't finished its last kick, do you?
Questions? Comments? Skepticism? Comment down below.