Animation won't play!

Hello all,

I’m making a game that involves a staff. This script is supposed to play an animation, but for some reason it won’t work. Here is the script.

local hitbox = script.Parent.Hitbox
local staff = script.Parent

-- ignore this function - it works fine
function onTouch(part)
	
	local character = part.Parent
	local player = game.Players:GetPlayerFromCharacter(character)

	-- if player exsists and can damage is true then deal damage
	if player then
	
			character.Humanoid:TakeDamage(21)
	
	end


end
staff.Hitbox.Touched:Connect(onTouch)

-- this is the one that doesn't play the animation
function yeetTheNoob()
	
	local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing):LoadAnimation()
	attack.AnimationId = 6527600949
	
	attack:Play()
	
end
script.Parent:Activate(yeetTheNoob)

There are no errors in the output.

Hope you all are enjoying your day,
@Mithrandir6440

	script.StaffSwing.AnimationId = "6527600949" -- i dont remember if this is an integer or a string.
local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing) -- make sure staffswing is animation instance.

	
	attack:Play()

try this

1 Like

Okay, so here is the new code:

‘’’'lua
local hitbox = script.Parent.Hitbox
local staff = script.Parent

– ignore this function - it works fine
function onTouch(part)

local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)

-- if player exsists and can damage is true then deal damage
if player then

		character.Humanoid:TakeDamage(21)

end

end
staff.Hitbox.Touched:Connect(onTouch)

– this is the one that doesn’t play the animation
function yeetTheNoob()

print('AA')

local staffSwing = script.StaffSwing

staffSwing.AnimationId = "6527600949"
local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing) 


attack:Play()

end
staff.Activated:Connect(yeetTheNoob)
‘’’

Here is the error:
SSerror1

And here is the explorer:
expl1

Many thanks!

I think you need to make “StaffSwing” a normal animation for it to have an AnimationId.
Either that or you need to submit the animation to Roblox to have a usable Id (while still using a normal animation) but I may be wrong on that.

How would I go about doing that? (The animation is already valid).

If you already have an AnimationId for an animation, I think you just need to change “StaffWing” into an animation instead of a KeyFrameSequence and try to set the Id to that, same script, different type of thing.

Humanoid:LoadAnimation() is deprecated.
Use Animator:LoadAnimation() on the Animator object inside the player’s character.

right click on the StaffSwing object, click Save to roblox, and at the end of saving it will give you an animation id

try inserting an animation into the staff (make sure to name it StaffSwing), looks like this,
Screenshot 2021-03-17 150100
then put the id in the AnimationId in the properties of the animation, then instead of writing this

change it to

local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing) --take away the extra load animation
	
	attack:Play()

This will work for now, until they remove the :LoadAnimation

Would just making a variable for the animator work better? I’m not too experienced with animations but I think this is how it would work.

local staffSwing = script.StaffSwing
local animator = staff.Parent.Humanoid.Animator

staffSwing.AnimationId = "6527600949"
local attack = animator:LoadAnimation(staffSwing)

attack:Play()
1 Like

Well, I would say that having it as an actual object in the explorer with the variable already inside is easier, and it is a method that I use that works. Your method probably works too, though I have never tried it. I am just giving @CJ_Nelson01 different options.

1 Like

This doesn’t work. I have a feeling that the animation is perhaps in the wrong place in the explorer…


I think you can get rid of the keyframes, just paste the animation ID in the AnimationId Property bar, inside
the StaffSwing

The format is: rbxassetid://id

local hitbox = script.Parent.Hitbox
local staff = script.Parent

-- ignore this function - it works fine
function onTouch(part)
	
	local character = part.Parent
	local player = game.Players:GetPlayerFromCharacter(character)

	-- if player exsists and can damage is true then deal damage
	if player then
	
			character.Humanoid:TakeDamage(21)
	
	end


end
staff.Hitbox.Touched:Connect(onTouch)

-- this is the one that doesn't play the animation
function yeetTheNoob()
	
	local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing):LoadAnimation()
	attack.AnimationId = "rbxassetid://6527600949"
	
	attack:Play()
	
end
script.Parent:Activate(yeetTheNoob)
1 Like

None of these suggestions work. I have removed keyframes, looked on the official website, and tried everyone else’s suggestions. I even tried this script that I created by myself.

‘’‘’
function yeetTheNoob()

local animator = script.Parent.Parent.Humanoid:WaitForChild('Animator')
local staffSwing = Instance.new('Animation')
staffSwing.AnimationId = 'rbxassetid://6527600949'
local staffSwingTrack = animator:LoadAnimation(staffSwing)
staffSwingTrack:Play()

end
script.Parent.Activated:Connect(yeetTheNoob)

‘’‘’

I feel like I’m kind of… out of options :frowning:

Check if the priority of the animation, it is probably still set on core

I think what you’re doing here should work, and I have no clue if I’m right about this but I’m thinking maybe try changing these lines

I think using ’ ’ instead of " " is the problem, so you could try doing

local animator = script.Parent.Parent.Humanoid:WaitForChild("Animator")
local staffSwing = Instance.new("Animation")
staffSwing.AnimationId = "rbxassetid://6527600949"

If this doesn’t work I’m out of ideas lol.

Oh, and I just learned what animation priority actually does, so what @MRKYLO20 suggested will probably be the fix to your problem.

1 Like

keyframes don’t belong in an animation, it should require the id, put the id in an animation object and copy the link from that and paste it into the script.

let me load a old script for a sword i made and see how i am able to load an animation so i can put this up further.

Hello all,

Many thanks to all who worked on this, but this issue has finally been solved. The issue was with the animation being incorrectly formatted and the animation priority being incorrect.

Hope you all are having a good day,
@Mithrandir6440