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

How do I fix the animation script?

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.

7 comments

0

Is this the whole script?

1

Yes

0

Edited. Try it now.

1

I did. Still doesn't work. Maybe It's my animation?

0

Add a print() statement inside the function, see if the function itself works. If it does, then double check on your animation. Make sure that its priority is set to "Action" in your case.

1

Didn't work.

0

Your print() function didn't work?

2 answers

✓ Accepted answer

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"

1 comment

0

Thank you!!!

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.

1 comment

1

Still doesn't work.... I suck at coding.

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