I need to make it so when I aim in, the aimpart of the gun and the arms are moved so that it looks like you’re aiming
I suck at math so I don’t know how to line it up correctly.
wait()
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftShoulder = torso:WaitForChild("Left Shoulder")
local camera = game.Workspace.CurrentCamera
updateSpeed = 0.1/1
local AimPartCFrame = nil
local Tool
local AimPart
game:GetService("RunService").RenderStepped:Connect(function()
--character["Right Arm"].LocalTransparencyModifier = character["Right Arm"].Transparency
--character["Left Arm"].LocalTransparencyModifier = character["Left Arm"].Transparency
local camCF = camera.CoordinateFrame
if character:FindFirstChild("Head") and character:FindFirstChild("Right Arm") and character:FindFirstChild("Left Arm") then
local distance = (character.Head.Position - camCF.p).magnitude
if distance <= 2 and humanoid.Health ~= 0 and character:FindFirstChild("Humanoid").Sit == false or distance <= 2 and humanoid.Health ~= 0 and character:FindFirstChild("Humanoid").Sit == true and character:FindFirstChildOfClass("Tool") then
if character:FindFirstChild("Aiming") and character:FindFirstChildOfClass("Tool") then
Tool = character:FindFirstChild("Aiming") and character:FindFirstChildOfClass("Tool")
if Tool:FindFirstChild("AimPart") and Tool:FindFirstChild("AimPart"):FindFirstChild("CFrame_Insert") then
local AimPart = Tool:FindFirstChild("AimPart")
local cf = camera.CFrame
local Difference = Tool.Handle.CFrame:ToObjectSpace(cf)
if AimPartCFrame == nil then
AimPartCFrame = CFrame.new(Tool:FindFirstChild("AimPart"):FindFirstChild("CFrame_Insert").Value.X - math.floor(Tool:FindFirstChild("AimPart"):FindFirstChild("CFrame_Insert").Value.X), Tool:FindFirstChild("AimPart"):FindFirstChild("CFrame_Insert").Value.Y - math.floor(Tool:FindFirstChild("AimPart"):FindFirstChild("CFrame_Insert").Value.Y) , Tool:FindFirstChild("AimPart"):FindFirstChild("CFrame_Insert").Value.Z - math.floor(Tool:FindFirstChild("AimPart"):FindFirstChild("CFrame_Insert").Value.Z))
end
if not character:FindFirstChild("Ledging") and not character:FindFirstChild("Zipping") then
rightShoulder.C0 = rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * AimPartCFrame * CFrame.Angles(0, math.pi/2, 0), updateSpeed)
leftShoulder.C0 = leftShoulder.C0:lerp((camCF * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * AimPartCFrame * CFrame.Angles(0, -math.pi/2, 0), updateSpeed)
else
rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
end
if game.UserInputService.MouseIconEnabled == true then
game.UserInputService.MouseIconEnabled = false
end
player.PlayerGui:WaitForChild("Crosshair").Enabled = true
end
end
else
if AimPartCFrame ~= nil then
AimPartCFrame = nil
end
rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
if game.UserInputService.MouseIconEnabled == false then
game.UserInputService.MouseIconEnabled = true
end
player.PlayerGui:WaitForChild("Crosshair").Enabled = false
end
end
end)