I have made a Hellmet-style gun system, but an uncalled-for roadblock has emerged. I have prepared a clip:
Medal clip:
Hellmet Roblox (Inspiration for the gun system): HELLMET [OPEN ALPHA] - Roblox
What is the issue? Well, when I walk backward, the hands seem to glitch out (Teleporting everywhere), and I have no clue what is going on. I have pondered the question for days, but I have not found a solution.
Here are the functions that I use to align the arms.
local function setup_arms()
local torso = character:FindFirstChild("Torso")
local right_shoulder = torso:FindFirstChild("Right Shoulder")
local left_shoulder = torso:FindFirstChild("Left Shoulder")
-- Store original C0 values for proper offsets
character:SetAttribute("RightShoulderC0", right_shoulder.C0)
character:SetAttribute("LeftShoulderC0", left_shoulder.C0)
end
local function point_arms()
local torso = character:FindFirstChild("Torso")
local right_shoulder = torso:FindFirstChild("Right Shoulder")
local left_shoulder = torso:FindFirstChild("Left Shoulder")
local rightC0Original = character:GetAttribute("RightShoulderC0")
local leftC0Original = character:GetAttribute("LeftShoulderC0")
-- Target positions in world space
local rightTargetWorld = current_gun.right_hand.Position
local leftTargetWorld = current_gun.left_hand.Position
-- Midway positions
local rightMidway = rightC0Original.Position:Lerp(torso.CFrame:PointToObjectSpace(rightTargetWorld), 0.5)
local leftMidway = leftC0Original.Position:Lerp(torso.CFrame:PointToObjectSpace(leftTargetWorld), 0.5)
-- Compute rotation to point at the target
local rightRotation = CFrame.lookAt(torso.CFrame:PointToWorldSpace(rightMidway), rightTargetWorld)
local leftRotation = CFrame.lookAt(torso.CFrame:PointToWorldSpace(leftMidway), leftTargetWorld)
-- Convert to torso's object space
rightRotation = torso.CFrame:ToObjectSpace(rightRotation)
leftRotation = torso.CFrame:ToObjectSpace(leftRotation)
-- Apply 90-degree correction around the X-axis
local rotationCorrection = CFrame.Angles(math.rad(90), 0, 0)
-- Apply new position and rotation
right_shoulder.C0 = CFrame.new(rightMidway) * rightRotation.Rotation * rotationCorrection
left_shoulder.C0 = CFrame.new(leftMidway) * leftRotation.Rotation * rotationCorrection
end