Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED]My sword works but the animation doesn't play?

Asked by 5 years ago
Edited 5 years ago

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!

0
i had same problem tacotown2 119 — 5y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

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

0
dont worry there was a problem in the animation StrategicPlayZ 58 — 5y
0
oh, well you might want to do this anyway, it would allow you to make keybinds SteamG00B 1633 — 5y
Ad

Answer this question