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

How Do You Animate A Sword?

Asked by 10 years ago

Hey. The problem with my script is that the sword is not going up into idle mode after I use it to slash. I'll save you the time reading the whole thing. The only real relative lines are 4-8, 10-14 and 137-141. Please take a few minutes to comb through that and see what I did wrong if you think you could be of any assistance.

Sword = script.Parent:GetChildren()
Tool = script.Parent

function SwordSlash()
    Tool.GripForward = Vector3.new(0,0,1)
    Tool.GripRight = Vector3.new(0,-1,0)
    Tool.GripUp = Vector3.new(-1,0,0)
end

function SwordIdle()
    Tool.GripForward = Vector3.new(0, 0, -1)
    Tool.GripRight = Vector3.new(1, 0, 0)
    Tool.GripUp = Vector3.new(0, 1, 0)
end

Tool.BladePart.Touched:connect(function (hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    if hit.Parent.Name == script.Parent.Name then return end
    if not Tool.Active.Value == true then return end
    hit.Parent.Humanoid:TakeDamage(10)
end)

Tool.BladePart2.Touched:connect(function (hit)
    if not hit.Parent:FindFirstChild("Humanoid") then return end
    if hit.Parent.Name == script.Parent.Name then return end
    if not Tool.Active.Value == true then return end
    hit.Parent.Humanoid:TakeDamage(10)
end)

function FadeIn()
    for i = 1, #Sword do
        if Sword[i]:IsA("Part") then
            Sword[i].Transparency = 0.9
            wait(.05)
            Sword[i].Transparency = 0.8
            wait(.05)
            Sword[i].Transparency = 0.8
            wait(.05)
            Sword[i].Transparency = 0.7
            wait(.05)
            Sword[i].Transparency = 0.6
            wait(.05)
            Sword[i].Transparency = 0.5
            wait(.05)
            Sword[i].Transparency = 0.4
            wait(.05)
            Sword[i].Transparency = 0.3
            wait(.05)
            Sword[i].Transparency = 0.2
            wait(.05)
            Sword[i].Transparency = 0.1
            wait(.05)
            Sword[i].Transparency = 0
            Sword[i].CanCollide = true
        elseif Sword[i]:IsA("WedgePart") then
            Sword[i].Transparency = 0.9
            wait(.05)
            Sword[i].Transparency = 0.8
            wait(.05)
            Sword[i].Transparency = 0.7
            wait(.05)
            Sword[i].Transparency = 0.6
            wait(.05)
            Sword[i].Transparency = 0.5
            wait(.05)
            Sword[i].Transparency = 0.4
            wait(.05)
            Sword[i].Transparency = 0.3
            wait(.05)
            Sword[i].Transparency = 0.2
            wait(.05)
            Sword[i].Transparency = 0.1
            wait(.05)
            Sword[i].Transparency = 0
            wait(.05)
            Sword[i].CanCollide = true
        end
    end
end

function FadeOut()
    for i = 1, #Sword do
        if Sword[i]:IsA("Part") then
            Sword[i].Transparency = 0.1
            wait(.05)
            Sword[i].Transparency = 0.2
            wait(.05)
            Sword[i].Transparency = 0.3
            wait(.05)
            Sword[i].Transparency = 0.4
            wait(.05)
            Sword[i].Transparency = 0.5
            wait(.05)
            Sword[i].Transparency = 0.6
            wait(.05)
            Sword[i].Transparency = 0.7
            wait(.05)
            Sword[i].Transparency = 0.8
            wait(.05)
            Sword[i].Transparency = 0.9
            wait(.05)
            Sword[i].Transparency = 1
            Sword[i].CanCollide = false
        elseif Sword[i]:IsA("WedgePart") then
            Sword[i].Transparency = 0.1
            wait(.05)
            Sword[i].Transparency = 0.2
            wait(.05)
            Sword[i].Transparency = 0.3
            wait(.05)
            Sword[i].Transparency = 0.4
            wait(.05)
            Sword[i].Transparency = 0.5
            wait(.05)
            Sword[i].Transparency = 0.6
            wait(.05)
            Sword[i].Transparency = 0.7
            wait(.05)
            Sword[i].Transparency = 0.8
            wait(.05)
            Sword[i].Transparency = 0.9
            wait(.05)
            Sword[i].Transparency = 1
            Sword[i].CanCollide = true
        end
    end
end


script.Parent.Equipped:connect(function (m)
    m.KeyDown:connect(function (key)
        if key == "q" then
            if script.Parent.Active.Value == false then
                script.Parent.Active.Value = true
                FadeIn()
                m.KeyDown:connect(function (key)
                    if key == "e" then
                        SwordSlash()
                        wait(1)
                        SwordIdle()
                    end
                end)
            elseif script.Parent.Active.Value == true then
                script.Parent.Active.Value = false
                FadeOut()
            end
        end 
    end)
end)

Thanks in advance.

Answer this question