I cant play an animation

I cannot play an animation, I am trying to make a player hold a gun with 2 hand when tool is equipeed. I know i have made a mistake but im not able to solve it, I would be really grateful for any help or advice.

image

i have looked thru many sites but to no help.
The ultimate goal is to loop the animation and play it when a tool is held.

image

here is the code:
local player = game.Players.LocalPlayer
local Character = player.Character
local Humanoid = Character:WaitForChild(“Humanoid”)
local Animator = Humanoid:WaitForChild(“Animator”)

local animation = Instance.new("Animation",script)
animation.AnimationId = "rbxassetid://6992692765"

local Anim = Animator:LoadAnimation(animation)


script.Parent.Ak.Equipped:Connect(function()
    Anim.looped = true
	Anim:Play()
end)
1 Like

Maybe try inserting an Animation Instance directly into the script?


Where is the LocalScript located? It is a direct child of the AK model?

image

i have already tried doing it as a direct child but that didnt work out

I think you can’t load animation to the Humanoid’s Animator, you have to load it in the Humanoid, just like this: Humanoid:LoadAnimation(animationInstance)

Of course you can. Actually LoadAnimation on Humanoid is deprecated.
@95elias95 Why not put the LocalScript in the tool and then edit it very simple?

1 Like

Oh, i’ve always used Humanoid:LoadAnimation(), but i went right now on the wiki and saw it is Deprecated, my bad.

didnt work out for me xd

i tried humanoid:loadanimation aswell as attempted to make script direct child
@Scefrom

image

Are you the owner of those animations?
If not, for player safety reasons, ROBLOX doesn’t allow you to play other’s animations in your games, you can only play animations that you have made or animations that ROBLOX have made.

What value are the AnimationPriority’s for the animations set to?
They should be set to action, to override movement + idle or else it won’t be able to override the idle animation and it won’t appear as playing for you.
See more here: AnimationPriority

I made the animation with the studio animator and set it to action, i probably missed something obvious. Thanks for helping, also @Mr_Mouseeee

The animation priority must be action, do you have the animation priority set to action?

1 Like

For this line;

You should use :WaitForChild() instead of just getting the character instantly or else it can return nil since your character might have not loaded yet, I think this is the problem. Try to switch it to:

local Character = player:WaitForChild("Character")

That sounds like it could be the issue but it apparently wasnt it. I also tried change the priority in teh script

image

it might be that the animation is messed up or smthing honestly idk

Try this!

local player = game.Players.LocalPlayer
local Character = player.Character
local Humanoid = Character:WaitForChild(“Humanoid”)

local animation = script.Parent.Animation

script.Parent.Ak.Equipped:Connect(function()
    animation:Play()
    animation:Loop = true
    -- Item Equipped, Animation has been Playyed
else
    script.Parent.Ak.Unequipped:Connect(function()
    animation:Stop()
    animation:Loop = false
    -- Player Has Unequipped the item and the animation has stopped
end)

Change this line

Because of this

local Character = player.Character or player.CharacterAdded:Wait()

something happened?

Why not just load the Animation ID in the Animator:LoadAnimation() instead?

Amm, it can’t, it has to be an instance

if not that, what do you mean?

You CAN use the animation id in the parameters. Tried it before and it works everytime.

@ItzMeZeus_IGotHacked
so i tried this and it didnt work, idk why.
image

also this didnt solve the problem
image

Thank you guys for helping out

edit: it might be the animations thats messed up

@StarJ3M I tried ur script and it didnt work xd

Did it really work? wow, but now he says no
image

maybe it was before Animation instance existed

Well, then it only means the animation instance is valid. Try parenting the animation instance to somewhere before loading it?

1 Like