I am creating an FPS arms script for my game, which works by modifying the Left and Right Shoulder Motor6Ds’ C0 properties every render step. It seems to stutter and lag behind and I’m not sure how to fix it. Here’s a video of the lag and the code.
Code:
local RunService = game:GetService("RunService")
local char = script.Parent
local torso = char.Torso
local hrp = char.HumanoidRootPart
local rightArm = char["Right Arm"]
local leftArm = char["Left Arm"]
local rightShoulder = torso["Right Shoulder"]
local leftShoulder = torso["Left Shoulder"]
local camera = game.Workspace.CurrentCamera
firstPerson = false
local function update()
rightArm.LocalTransparencyModifier = rightArm.Transparency
leftArm.LocalTransparencyModifier = leftArm.Transparency
local distance = (hrp.Position + hrp.CFrame.UpVector * 1.5 - camera.CoordinateFrame.Position).Magnitude
if distance <= 1 then
if firstPerson == false then
firstPerson = true
return
end
rightShoulder.C0 = (camera.CoordinateFrame * CFrame.new(1, -1, 0)):ToObjectSpace(torso.CFrame):Inverse() * CFrame.Angles(0, math.pi/2, 0)
leftShoulder.C0 = (camera.CoordinateFrame * CFrame.new(-1, -1, 0)):ToObjectSpace(torso.CFrame):Inverse() * CFrame.Angles(0, -math.pi/2, 0)
else
if firstPerson == true then
firstPerson = false
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
end
end
RunService:BindToRenderStep("update", Enum.RenderPriority.Camera.Value + 1, update)