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

How can I stop a reload sequence midway?

Asked by 10 years ago

Ok so I have a gun system that has a reload sequence, and what I'm trying to do is have the reload sequence stop whenever a variable called BreakReload is changed. I'll provide the code:

function ReloadAnim()
    _G.TweenJoint(_G.LWeld2,CF(),CF(),_G.Sine,0.15)
    _G.TweenJoint(_G.RWeld2,CF(),CF(),_G.Sine,0.15)
    local Speed = (ReloadTime.Value / 3)
    Gun.Mag1.Transparency,Gun.Mag2.Transparency = 1,1
    local Mag1Clone1,Mag2Clone1 = Gun.Mag1:Clone(),Gun.Mag2:Clone()
    Mag1Clone1.Transparency,Mag2Clone1.Transparency = 0,0
    Mag1Clone1.Name,Mag2Clone1.Name = "Mag1Clone1","Mag2Clone1"
    Mag1Clone1.CanCollide,Mag2Clone1.CanCollide = true,true
    Mag1Clone1.Parent,Mag2Clone1.Parent = _G.TextureFolder,_G.TextureFolder
    local Weld1 = Instance.new("Weld",Mag1Clone1)
    Weld1.Part0 = Mag2Clone1
    Weld1.Part1 = Mag1Clone1
    Weld1.C0 = Gun.Mag2.CFrame:toObjectSpace(Gun.Mag1.CFrame)
    local Weld2 = Instance.new("Weld",Mag1Clone1)
    Weld2.Part0 = Mag1Clone1
    Weld2.Part1 = Gun.Mag1
    _G.TweenJoint(_G.LWeld,_G.ArmC0[1],CF(0,0.61,0) * CFANG(RAD(70),0,0),_G.Linear,0.7 * Speed)
    _G.TweenJoint(_G.RWeld,_G.ArmC0[2],(CF(0.7,-0.01,-0.21) + VEC3(-0.3,0.1,0)) * CFANG(RAD(-20),RAD(3),RAD(0)),_G.Linear,0.5 * Speed)
    _G.TweenJoint(_G.RightGrip,GripC0,CFANG(0,RAD(10),0),_G.Linear,0.5 * Speed)
    wait(0.5 * Speed)
    _G.TweenJoint(_G.RWeld,_G.ArmC0[2],(CF(0.7,-0.01,-0.21) + VEC3(-0.3,0,-0.1)) * CFANG(RAD(-22),RAD(3),RAD(0)),_G.Sine,0.3 * Speed)
    wait(0.2 * Speed)
    Weld2:Destroy()
    Mag1Clone1.Velocity = Gun.Mag1.Velocity + (Mag1Clone1.CFrame * CFANG(0,RAD(90),0)).lookVector * 20
    Spawn(function()
        while Mag1Clone1.Velocity.magnitude > 0.1 do wait() end
        Mag1Clone1.Anchored = true
        Mag2Clone1.Anchored = true
    end)
    delay(5,function()
        Mag1Clone1:Destroy()
        Mag2Clone1:Destroy()
    end)
    local Mag1Clone2,Mag2Clone2 = Gun.Mag1:Clone(),Gun.Mag2:Clone()
    Mag1Clone2.Transparency,Mag2Clone2.Transparency = 0,0
    Mag1Clone2.Name,Mag2Clone2.Name = "Mag1Clone2","Mag2Clone2"
    Mag1Clone2.Parent,Mag2Clone2.Parent = _G.TextureFolder,_G.TextureFolder
    local Weld3 = Instance.new("Weld",Mag1Clone2)
    Weld3.Part0 = Mag2Clone2
    Weld3.Part1 = Mag1Clone2
    Weld3.C0 = Gun.Mag2.CFrame:toObjectSpace(Gun.Mag1.CFrame)
    local Weld4 = Instance.new("Weld",Mag1Clone2)
    Weld4.Part0 = _G.FakeLArm
    Weld4.Part1 = Mag1Clone2
    Weld4.C0 = CF(0.041009903,-1.29957438,0.538218021) * CFANG(0.831322253,0.696440935,-1.17165649)
    wait(0.1)
    _G.TweenJoint(_G.LWeld,_G.ArmC0[1],(CF(-0.7,1.55,-0.21) + VEC3(1,0.3,-0.1)) * CFANG(RAD(-20),RAD(30),RAD(-60)),_G.Sine,0.7 * Speed)
    _G.TweenJoint(_G.RWeld,_G.ArmC0[2],(CF(0.7,-0.01,-0.21) + VEC3(-0.3,0,0)) * CFANG(RAD(-20),RAD(35),RAD(0)),_G.Sine,0.7 * Speed)
    wait(0.7 * Speed)
    Mag1Clone2:Destroy()
    Mag2Clone2:Destroy()
    Gun.Mag1.Transparency,Gun.Mag2.Transparency = 0,0
    _G.TweenJoint(_G.LWeld,_G.ArmC0[1],CF(-0.7,1.55,-0.21) * CFANG(RAD(-10),0,RAD(-30)),_G.Sine,0.5 * Speed)
    _G.TweenJoint(_G.RWeld,_G.ArmC0[2],CF(0.7,-0.01,-0.21) * CFANG(RAD(-10),0,RAD(15)),_G.Sine,0.5 * Speed)
    _G.TweenJoint(_G.RightGrip,GripC0,CFANG(0,RAD(20),0),_G.Linear,0.5 * Speed)
    wait(0.5 * Speed)
    _G.TweenJoint(_G.LWeld,_G.ArmC0[1],(CF(-0.7,1.55,-0.21) - VEC3(0.3,0.7,0)) * CFANG(RAD(-10),0,RAD(-40)),_G.Linear,0.25 * Speed)
    wait(0.25 * Speed)
    Action1()
    _G.TweenJoint(_G.LWeld,_G.ArmC0[1],CF(-0.7,1.55,-0.21) * CFANG(RAD(-10),0,RAD(-30)),_G.Linear,0.25 * Speed)
    wait(0.25 * Speed)
    Action2()
    _G.TweenJoint(_G.LWeld,_G.ArmC0[1],ArmC1[1],_G.Sine,0.5 * Speed)
    _G.TweenJoint(_G.RWeld,_G.ArmC0[2],ArmC1[2],_G.Sine,0.5 * Speed)
    wait(0.5 * Speed)
end

I've tried to have a conditional above every line that returns end if BreakReload is true, but I realized that that wouldn't work properly. Any suggestions or ideas as to how I may go with this?

0
Omg wow... You're either way better than me or this isn't Lua O.O Perci1 4988 — 10y
0
Heh, I put a lot of work into my guns. They're pretty advanced TurboFusion 1821 — 10y
0
Most of that looks like animations, so why don't you just use Roblox's animation editor instead? Perci1 4988 — 10y
0
My tool has welds, lots of them, and I can't use a Roblox animation on Welds TurboFusion 1821 — 10y

Answer this question