Hello, I’m a beginner, and I’m scripting a sword with custom animation when equipped and when you walk. But also, when you hit any npc/user it will run an animation of getting sliced.
The attack animation work perfectly, but when I attack with it, it gives me an error (the damage doesn’t works, the “sliced” animation doesn’t actives). and I have no idea how to fix it.
However, sometimes it does damage and the sliced animation works. (Usually at exact positions or when you attack while jumping) And when it does works, the error doesn’t appear.
My thoughts is that It may be something related to hitbox but I’m not sure because of the error.
function onTouch(hit)
script.Disabled = true
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local animation = script.Animation
local animationtrack = humanoid:LoadAnimation(animation)--This is the line that gives error
animationtrack:Play()
humanoid.Health = humanoid.Health - 10
end
script.Parent.Touched:Connect(onTouch)
This is how the sword is structured, so you can get a better idea overall.
The red lines indicates wich script runs when attacking and the animation that it uses.
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if not humanoid then return end -- Will return if humanoid doesn't exist
local animation = script.Animation
local animationtrack = humanoid:LoadAnimation(animation)--This is the line that gives error
animationtrack:Play()
Side Note: Humanoid:LoadAnimation() is deprecated, use Humanoid.Animator
Thanks It does works!, now I’ll have to figure out how to use debounce or something like that on it because it does constant damage (but that is out of the original problem that you were answering, thank you!)