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

How do I fix the animation script?

Asked by 8 years ago
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.

0
Is this the whole script? Redbullusa 1580 — 8y
1
Yes 64batsalex 45 — 8y
0
Edited. Try it now. Redbullusa 1580 — 8y
1
I did. Still doesn't work. Maybe It's my animation? 64batsalex 45 — 8y
View all comments (3 more)
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. Redbullusa 1580 — 8y
1
Didn't work. 64batsalex 45 — 8y
0
Your print() function didn't work? Redbullusa 1580 — 8y

2 answers

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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"
0
Thank you!!! 64batsalex 45 — 8y
Ad
Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
8 years ago

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
Still doesn't work.... I suck at coding. 64batsalex 45 — 8y

Answer this question