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

How to edit position of arms in a gun weld?

Asked by 8 years ago

Here is the script. For the function welding.Holster, I want the arms to be positioned closer to the body, so that the gun barrel is a lot closer to the left leg. Currently it is way too far out.

This is what it currently looks like when in the sprinting position: 1 2 3

How would I edit the welding to do this?

wait(0.2)
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local tool = script.Parent

local crouching,sprinting = false,false
local welding = {}
local cframe, cframeXYZ, vector = CFrame.new, CFrame.fromEulerAnglesXYZ, Vector3.new
local create = assert(LoadLibrary("RbxUtility")).Create
welding.Weld = create("Weld"){}
local leftCrouchWeld, rightCrouchWeld = create("Weld"){}, create("Weld"){}
local arms = {
    Left = cframe(0.9,0.8,0.5) * cframeXYZ(math.rad(280),math.rad(40),math.rad(-2)),
    Right = cframe(-1,0.1,0.35) * cframeXYZ(math.rad(-90),math.rad(-15),math.rad(0)),
}

function welding.SetArms(bool)
    local torso = char:FindFirstChild("Torso")
    local leftS, rightS = torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")
    local left, right = char:FindFirstChild("Left Arm"), char:FindFirstChild("Right Arm")
    if bool then
        leftS.Part1, rightS.Part1 = nil, nil
        leftWeld = welding.Weld:Clone()
            leftWeld.Name = "Weld1"; leftWeld.Part0 = torso; leftWeld.Part1 = left; leftWeld.C1 = arms.Left; leftWeld.Parent = torso
        rightWeld = welding.Weld:Clone()
            rightWeld.Name = "Weld2"; rightWeld.Part0 = torso; rightWeld.Part1 = right; rightWeld.C1 = arms.Right; rightWeld.Parent = torso
        FakeLeftArm, FakeRightArm = left:Clone(), right:Clone()
        FakeLeftArm:ClearAllChildren()
        FakeLeftArm.Name = "FakeLeftArm"
        FakeLeftArm.FormFactor = "Custom"
        FakeLeftArm.Size = Vector3.new(0.9, 1.75, 0.9)
        FakeLeftArm.Transparency = 0.6
        FakeLeftArm.Parent = tool
        local flaWeld = welding.Weld:Clone()
        flaWeld.Parent = FakeLeftArm; flaWeld.Part0 = left; flaWeld.Part1 = FakeLeftArm
        FakeRightArm.Name = "FakeRightArm"
        FakeRightArm:ClearAllChildren()
        FakeRightArm.FormFactor = "Custom"
        FakeRightArm.Size = Vector3.new(0.9, 1.75, 0.9)
        FakeRightArm.Transparency = 0.6
        FakeRightArm.Parent = tool
        local fraWeld = welding.Weld:Clone()
        fraWeld.Parent = FakeRightArm; fraWeld.Part0 = right; fraWeld.Part1 = FakeRightArm
    else
        sprinting = false
        char.Humanoid.WalkSpeed = 16
        leftS.Part1, rightS.Part1 = left, right
        if leftWeld and rightWeld then
            leftWeld:Destroy()
            rightWeld:Destroy()
        end
        if FakeLeftArm and FakeRightArm then
            FakeLeftArm:Destroy()
            FakeRightArm:Destroy()
        end
    end
end

function welding.Default(...)
    if char and char:FindFirstChild("Torso") and char.Torso:FindFirstChild("Weld1") and char.Torso:FindFirstChild("Weld2") then
        local Left = char.Torso:FindFirstChild("Weld1")
        local Right = char.Torso:FindFirstChild("Weld2")
        Left.C1 = arms.Left
        Right.C1 = arms.Right
        char.Humanoid.WalkSpeed = 16
    end
end

function welding.Holster(...)
    local left = char.Torso:FindFirstChild("Weld1")
    local right = char.Torso:FindFirstChild("Weld2")

    right.C1 = right.C1 * CFrame.Angles(math.pi/6, -math.pi/6, 0) * CFrame.new(-0.5, 0.1, 0)
    left.C1 = left.C1 * CFrame.Angles(math.pi/6, 0, 0) * CFrame.new(0.5, -0.5, -0.5)
end

function welding.Crouch(bool)
    if bool then
        if char:FindFirstChild('Left Leg') and char:findFirstChild('Right Leg') and char:findFirstChild('HumanoidRootPart') and char.HumanoidRootPart:findFirstChild('RootJoint') and char.Torso and char.Torso:findFirstChild('Left Hip') and char.Torso:findFirstChild('Right Hip') then
            char.Torso['Right Hip'].Part1 = nil
            char.Torso['Left Hip'].Part1 = nil
            char.HumanoidRootPart.RootJoint.C1 = CFrame.new(0,1,0)*CFrame.Angles(math.rad(90),math.rad(180),0)
            leftCrouchWeld.Part0 = char.Torso leftCrouchWeld.Parent = char.Torso leftCrouchWeld.Part1 = char['Left Leg']
            rightCrouchWeld.Part0 = char.Torso rightCrouchWeld.Parent = char.Torso rightCrouchWeld.Part1 = char['Right Leg']
            leftCrouchWeld.C1 = CFrame.new(.5,.5,1.5)*CFrame.Angles(math.rad(90),0,0)
            rightCrouchWeld.C1 = CFrame.new(-.55,1.3,.5)*CFrame.Angles(math.rad(-15),0,0)
        end
    else
        if char:findFirstChild('Left Leg') and char:findFirstChild('Right Leg') and char:findFirstChild('HumanoidRootPart') and char.HumanoidRootPart:findFirstChild('RootJoint') and char.Torso and char.Torso:findFirstChild('Left Hip') and char.Torso:findFirstChild('Right Hip') then
            char.Torso['Right Hip'].Part1 = char['Right Leg']
            char.Torso['Left Hip'].Part1 = char['Left Leg']
            char.HumanoidRootPart.RootJoint.C1 = CFrame.new(0,0,0)*CFrame.Angles(math.rad(90),math.rad(180),0)
            leftCrouchWeld.Parent = nil rightCrouchWeld.Parent = nil
        end
    end
end

script.Parent.Equipped:connect(function()
    wait()
    welding.SetArms(true)
    repeat wait() until _G.Values
    _G.Values.Sprinting = false
    sprinting = false
    if plr.PlayerGui:FindFirstChild('GunGUI') then
        plr.PlayerGui.GunGUI.BackImage.Image = 'rbxassetid://121162024'
    end
end)

script.Parent.Unequipped:connect(function()
    wait()
    welding.SetArms(false)
    if crouching then
        crouching = false
        char.Humanoid.WalkSpeed = 16
        _G.Values.Sprinting = false
        welding.Crouch(false)
    end
end)

_G.FDown = function()
    if sprinting then
        sprinting = false
        char.Humanoid.WalkSpeed = 16
        _G.Values.Sprinting = false
        welding.Default()
    else
        sprinting = true
        crouching = false
        char.Humanoid.WalkSpeed = 22
        _G.Values.Sprinting = true
        welding.Holster()
        welding.Crouch(false)
    end
end

_G.CDown = function()
    if crouching then
        crouching = false
        char.Humanoid.WalkSpeed = 16
        _G.Values.Sprinting = false
        welding.Crouch(false)
    else
        sprinting = false
        crouching = true
        char.Humanoid.WalkSpeed = 10
        welding.Default()
        _G.Values.Sprinting = false
        welding.Crouch(true)
    end
end

_G.Mouse2Down = function(mouse)
    if sprinting then
        sprinting = false
        char.Humanoid.WalkSpeed = 16
        _G.Values.Sprinting = false
        _G.MouseTrue()
        welding.Default()
        _G.Mouse1Down(mouse)
    end
end

Answer this question