In Lines 6 and 7, you try passing off a number value (assuming its the animation ID) within the parameters of the function(s). Problem with that is the script isn't going to know what to do with those values, they are just there. There are a number of workarounds for this problem, but here's what I would do in this scenario:
Place the LocalScript inside of StarterPack , and insert an Animation object directly inside of that script. It should look something like this now:
Click here to view image.
Click on the Animation object and inside the AnimationId property, let's enter in the asset URL in order for the script to be able to locate it: rbxassetid://319782924
View the GIF here if you have any troubles.
Sweet, now that we got the animation set up, let's head into the actual scripting. I find it better to use UserInputService instead of KeyDown events (especially across multiple platforms), but it works either way in this case.
local deb = false
local key_input = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player.Character
local char = player.Character
local anim = script:WaitForChild("Animation")
key_input.InputBegan:connect(function(key)
if (key.KeyCode == Enum.KeyCode.Q) and not deb then
deb = true
local animtrack = char.Humanoid:LoadAnimation(anim)
animtrack:Play()
print("Playing animation...")
end
wait(1)
deb = false
end)
We should now have a working animation script that runs whenever the Q key is pressed! Here is a preview of how the script should work (NOTE: I'm using one of my own animations for this test):
Preview GIF.
Questions / comments? Feel free to message me and I'll answer them as soon as possible. If you are satisfied with the answer I provided, please upvote me. Thanks!
7 comments
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(key) if (key == "q") then local currentAnimTrack = Player.Character.Humanoid:LoadAnimation(319782924) currentAnimTrack:Play() end end) it doesn't work like this
i stil dont get it but i will try
ty
really?!? thats so nice of you thanks!!!
i know how to make a jump animation but the thing is i wanted something else i wanted that if player presses Q it plays 319782924 its my selfcreated animation it is not a jumping animation or a running one its a action
just get in a certain stand
ty