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

Problem? Yes I have a problem with the left arm of aiming script!

Asked by 5 years ago

Hello! I need with a script, I tried to make that the left arm can move on the aiming script... But it's doing some strange things... Can someone help?

repeat wait() until workspace:findFirstChild(game.Players.LocalPlayer.Name)
wait()

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character
local hastool = false
local armweld = player.Character.Torso["Right Shoulder"]
local origarmweldcf = armweld.C0
local basearmweldcf = origarmweldcf + Vector3.new(0,0.25,-0.25)
local baseheadweldcf = char.Torso.Neck.C1
local heading, attitude, bank

local cam2 = workspace.CurrentCamera
local player2 = game.Players.LocalPlayer
local char2 = player.Character
local hastool2 = false
local armweld2 = player.Character.Torso["Left Shoulder"]
local origarmweldcf2 = armweld.C0
local basearmweldcf2 = origarmweldcf + Vector3.new(0,-0.25,0.25)
local baseheadweldcf2 = char.Torso.Neck.C1
local heading, attitude, bank

function holdingtool()
    for _,instance in ipairs(char:GetChildren()) do
        if instance:IsA("Tool") then
            return true
        end
    end
end

cam.Changed:connect(function()  

    local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cam.CoordinateFrame:components()
    heading = math.atan2(m02, m22)
    attitude = math.asin(-m12)
    bank = math.atan2(m10, m11)

    if hastool then
        armweld.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
    end

    char.Torso.Neck.C1 = baseheadweldcf*CFrame.Angles(attitude,0,0)

    local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cam.CoordinateFrame:components()
    heading = math.atan2(m02, m22)
    attitude = math.asin(-m12)
    bank = math.atan2(m10, m11)

    if hastool then
        armweld.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
    end

    char.Torso.Neck.C1 = baseheadweldcf*CFrame.Angles(attitude,0,0)

end)

char.ChildAdded:connect(function(child)
    if child:IsA("Tool") then
        hastool = true
        armweld.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
    end
end)

char.ChildAdded:connect(function(child)
    if child:IsA("Tool") then
        hastool = true
        armweld2.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
    end
end)

char.ChildRemoved:connect(function()
    wait()
    if not holdingtool() then
        hastool = false
        armweld.C0 = origarmweldcf
    end
end)

char.ChildRemoved:connect(function()
    wait()
    if not holdingtool() then
        hastool = false
        armweld2.C0 = origarmweldcf
    end
end)

Answer this question