How to play custom animation

Hello! Im currently trying to make a tool to play animation, this is the code :

    local player = game.Players.LocalPlayer
    repeat wait() until player.Character.Humanoid
    local humanoid = player.Character.Humanoid
    local mouse = player:GetMouse()
    local tool = script.Parent

    local anim = Instance.new("Animation")
    anim.AnimationId = "http://www.roblox.com/asset/?id=5454739249"

    function rollplay()
    	local pAnimm = humanoid:LoadAnimation(anim)
    	pAnimm:Play()
    	print("roll!")
    end

    tool.Activated:Connect(rollplay)

But there is nothing happened!, “roll!” also not writed on output. Is there anything wrong? if yes, please tell me. I got the code from developer.roblox.com and then edit it some. I has been tried to edit deafult animation from that web too, but nothing happened. I tried many tutorial (using keybind to play animation, using mouseclick, using textbutton on gui) but nothing happened too. I really need help right now :frowning:

Thanks for your reply!

4 Likes

Did you put this in a local script? Also does the “roll” print if you remove all the animation code?

First of all in the animation id use this format: “rbxassetid://(IDHere)”

Second you did not set a parent for the animation, so do “anim.Parent = humanoid”

See if this works.

Try this:

local plr = game.Players.LocalPlayer
local tool = script.Parent

function rollplay()
	local anim = Instance.new("Animation", plr.Character)
	anim.AnimationId = "http://www.roblox.com/asset/?id=5454739249"
	local pAnimm = plr.Character:WaitForChild("Humanoid"):LoadAnimation(anim)
	pAnimm:Play()
	print("roll!")
end

tool.Activated:Connect(rollplay)

Yes, i put it in a local script. First time it wont print, but after i put a handle it printed

1 Like

I used it before i change to http://www.roblox.com/asset/?id=5454739249 and it doesnt working (then i change it back to rbxassetid://5454739249 but not working too).

Um, this is my 5th day scripting so idk where should i put it. But i put anim.Parent = humanoid
under anim.AnimationID (is it wrong?) and the animation still wont play

It doesnt work too, but “roll!” printed in output.

Hey, is this particular animation made by you or someone else in your team? I’ve faced similar problems with animations that aren’t owned by me.

Edit: Never mind, stupid question. Have you tried changing the animation priority in the editor to “movement” or “action” so it overrides the default animations?

Are u using team create or is the game made by a group?, If so publish the animation the the group

I think the animation is his. I checked the asset ID

Yes I did. I tried both but the animation still wont played

Is the tool itself the parent of the local script?

Yep. I placed my local script inside the tool

at the animationID line change http to https, roblox does not trust HTTP links

Is the avatar R6 or R15, if the animation is using a different model other than the avatar it wont work
Try changing the avatar model in the game’s settings to R6 and then R15 and see which one works

4 Likes

and make sure your logged in as Minecrafterlikers in studio. Any other account and this animation will never load.

1 Like

Oh its work! I though R6 animation work on R15 character.

2 Likes