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

Why won't this welding work to make the arms follow the mouse?

Asked by 9 years ago

So, I want to offset the arm and the head so the head is in its normal spot and the arms and head follow the mouse, but whats happening is the head gets stuck in the arm, the head then does not move at all, probably because its been welded before the head follow mouse code block is run. Any help appreciated, I'm using this source --https://scriptinghelpers.org/questions/17657/make-arms-follow-mouse-like-fps -- credit to Spongocardo for the head follow mouse code block.

--variables
Cam = game.Workspace.CurrentCamera
Tool = script.Parent
Barrel = Tool:WaitForChild("Barrel")
Handle = Tool:WaitForChild("Handle")

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Character = Player.Character

Head = Character:WaitForChild("Head")
Torso = Character:WaitForChild("Torso")
HumRootPart = Character:WaitForChild("HumanoidRootPart")
LArm = Character:WaitForChild("Left Arm")
RArm = Character:WaitForChild("Right Arm")
LLeg = Character:WaitForChild("Left Leg")
RLeg = Character:WaitForChild("Right Leg")

function Equipped()
    --[[
    local RAWeld = Instance.new("Weld")
    RAWeld.Parent = Character
    RAWeld.Part0 = Head
    RAWeld.Part1 = RArm
    RAWeld.C1 = CFrame.new(0,0,0)
    ]]--

    local LAWeld = Instance.new("Weld")
    LAWeld.Parent = Character
    LAWeld.Part0 = Head
    LAWeld.Part1 = LArm
    LAWeld.C1 = CFrame.new(0, 0, 0)--doesn't seperate head with arm

    game:GetService("RunService").RenderStepped:connect(function() --Runs the function each time a frame is rendered.
    Mouse.TargetFilter = workspace --This is important when setting the C0 at the bottom as it ignores everything in the workspace to give clean movement of the arms on the Y axis.
    Player.Character.Torso.Neck.C1 = CFrame.new() --Sets the C1 to a blank CFrame so the head doesn't glitch.
    Player.Character.Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), 0, 0) --Moves the head up by 1.5 studs and then sets the angle of your character's neck looking up towards the mouse using inverse trigonometry (A grade maths) and unit vectors (so you only get the direction.)
    end)
end

Answer this question