Animation won't run ;-; (R15)

so basically i try to make add sword a animation but it’s just don’t run, it’s placed here

SwordScript:

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://3493431823"
local animTrack
local tool = script.Parent
local char

tool.Activated:Connect(function()
local char = tool.Parent
animTrack = char.Humanoid:LoadAnimation(animation)
animTrack:Play()
local dmg = script.Damage:Clone()
dmg.Parent = tool.Handle
dmg.Disabled = false
wait(animTrack.Length)
if dmg then
dmg:Destroy()
end
end)
tool.Unequipped:Connect(function()
if animTrack then
animTrack:Stop()
end

end)

damage script:

local weapon = script.Parent
local dmg = 5

weapon.Touched:connect(function(part)
	if part.Parent:findFirstChild("Humanoid") then
		local humanoid = part.Parent:findFirstChild("Humanoid")
		humanoid:TakeDamage(dmg)
		script:Destroy()
	end
end)

please help me, i have this bug a month already and i have no idea how to solve it, thanks in advance :slight_smile:

It’d be nice if you did some prior debugging first, which there is no indication of. When a script doesn’t work, the first thing you should be doing is checking your console for an error and a stack trace, not posting here.

Does your script error in any way?

On a separate note, some comments on your code:

  • There’s no need to instance the animation at run time.
  • There’s no debounce for actions. You should include one.
  • You should use an internal value as a flag to activate damage rather than an external script.

there’s no error in the console, it’s just won’t run

What specifically isn’t working? Is it only the animation? Ensure that the rest of your code is running in the first place.

If the rest of your code is functional aside from the animation, then it’s most likely to do with the animation itself. The most common case of error is failing to use an appropriate animation priority. In this case, you’d probably want Action.

1 Like

my sword does damage but the animation just won’t run

Check the animation priority with code or via the Animation Editor. To check the priority with code, add this before you call play:

print(animtrack.Priority)

If it’s Core, it’s getting overridden by default animations. Change the priority in an animation editor if so, update the animation and try again. You can also set it with code.

animtrack.Priority = Enum.AnimationPriority.Action
1 Like

it first prints Enum.AnimationPriority.Action and when i try to attack again it prints Enum.AnimationPriority.Core

That’s the issue then. You uploaded an animation with a priority of Core.

Go back to your Animation Editor and find the load option. Select the animation you uploaded and make sure it loads. Then, find the priority option and set it to Action. Once that’s done, select Export (or whatever the upload option is) and overwrite the animation you last uploaded.

This will repair your problem.

2 Likes

yayy it worked, but i can spam the animation , how i can make the animation to play until the end and then i can attack again?
https://gyazo.com/a09786a1136879e24d31eeea4f992de8

Different topic altogether, which I mentioned in my first post:

local debounce = false

Activated:Connect(function ()
    if not debounce then
        debounce = true
        -- Swing code
        -- Somewhere after the animation ends:
        debounce = false
    end
end)
1 Like

ok it’s worked, thanks for everything :smiley: , finally i can move on on other things thank to you