So, I’m making a shooter, and I want the arms to follow the mouse position. So, I found a script that does that, but it doesn’t work well with my current script.
scripts:
client (happens every step):
character["Right Arm"].LocalTransparencyModifier = character["Right Arm"].Transparency
character["Left Arm"].LocalTransparencyModifier = character["Left Arm"].Transparency
local camCF = camera.CoordinateFrame
local distance = (character.Head.Position - camCF.p).magnitude
if distance <= 2 and humanoid.Health ~= 0 then
rightShoulder.C0 = rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), updateSpeed)
leftShoulder.C0 = leftShoulder.C0:lerp((camCF * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * 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
server happens when the player’s mouse moves:
local RenderService = game:GetService("RunService")
local ToolMotor = Instance.new("Motor6D")
ToolMotor.Parent = character:WaitForChild("HumanoidRootPart")
local mousePosition = Vector3.new(0, 0, 0)
ArmsEvent.OnServerEvent:Connect(function(plr, position)
if plr == player then
mousePosition = position
end
end)
local RightShoulder, LeftShoulder, ToolGrip = character.Torso:WaitForChild("Right Shoulder"), character.Torso:WaitForChild("Left Shoulder"), ToolMotor
RenderService.Heartbeat:Connect(function()
local X = -(math.asin((character.HumanoidRootPart.Position - mousePosition).unit.y))
local _, Y, Z = RightShoulder.C0:ToEulerAnglesXYZ()
local OldRightC0 = RightShoulder.C0
RightShoulder.C0 = CFrame.new(RightShoulder.C0.Position) * CFrame.Angles(X, Y, Z)
local Difference = OldRightC0.Position - RightShoulder.C0.Position
local _, Y, Z = ToolGrip.C0:ToEulerAnglesXYZ()
ToolGrip.C0 = CFrame.new(ToolGrip.C0.Position) * CFrame.Angles(X, Y, Z)
local _, Y, Z = LeftShoulder.C0:ToEulerAnglesXYZ()
LeftShoulder.C0 = CFrame.new(LeftShoulder.C0.Position) * CFrame.Angles(X, Y, Z)
end)