I am trying to make a sword in my game, but it's animation is not playing for some reason, but other things are working, such as the opponent is being damaged by the sword, but the animation is not playing. Please tell me what is the problem with my script, and what actions I can take to fix it.
Here is the script:
local blade = script.Parent.Handle.Blade local CanDamage = script.Parent.CanDamage local CanAttack = true local damage = 30 script.Parent.Equipped:Connect(function() local human = script.Parent.Parent.Humanoid local attack = human:LoadAnimation(script.Parent.Attack) end) script.Parent.Activated:Connect(function() local human = script.Parent.Parent.Humanoid if CanAttack == true then local attack = human:LoadAnimation(script.Parent.Attack) attack:Play() CanAttack = false CanDamage.Value = true wait(1.3) attack:Stop() CanAttack = true CanDamage.Value = false end end) blade.Touched:Connect(function(hit) local human = hit.Parent.Humanoid if human then if CanDamage.Value == true then if human.Parent.Name ~= script.Parent.Parent.Name then human:TakeDamage(damage) end end end end)
Thanks!
You seem to have your script inside the animation, so you can't trigger the animation within the thing that detects if it was triggered.
script.Parent.Activated:Connect(function()
You're going to need to change this up so that instead of the function above gets triggered, you'll have a boolean value that switches in your mouse press event or keypress event, whichever one you chose, it switches the boolean value. So that in this script, you just check for a change in the boolean value, and if it changes, then you play the animation.
Workspace.BoolValue.Changed:Connect(function(NewValue) --you would just change this to wherever you keep the BoolValue object local human = script.Parent.Parent.Humanoid if CanAttack == true then local attack = human:LoadAnimation(script.Parent.Attack) attack:Play() CanAttack = false CanDamage.Value = true wait(1.3) attack:Stop() CanAttack = true CanDamage.Value = false end end)
If this answers your question, then please mark it as the accepted answer