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

how can i animate a player?

I am trying to animate and watched a video about it, but for some reason the code works on a npc, but not on a player:

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=1574345273"

local trackanimation = nil
local playability = true
function playAnimation(AnimationSource)
	if playability == true then
		local plr = game.Players.LocalPlayer
		trackanimation = plr.Character:WaitForChild("Humanoid"):LoadAnimation(animation)
		trackanimation.KeyframeReached:Connect(function()
			print("Works")
		end)
		trackanimation:Play()
		print("play")
	end
end

script.Parent.MouseButton1Click:Connect(playAnimation)

2 comments

0

Please code block your code. To do so, highlight your code then press the blue Lua button (It's near Bold, Italic, etc). Or press the code block button then paste your code within.

0

thanks, ill edit it

2 answers

✓ Accepted answer

It works on an NPC because it's in a ServerScript.

You probably need a LocalScript,

It's likely your animation is being overlapped by the movement animations that Roblox has put in place by default - circumvent this by going in the animation editor - going to "Edit" in the plugin, and then changing the animation priority to whatever the bottom one is - I believe it is movement, which is the highest level animation. After you set it to the highest level animation priority, reexport it to Roblox, overwriting your previous animation.

Let me know if this helps any. :)

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