I made a Tool gun (Serbu BFG 50) and it uses the Torso as it’s weld, because of the equip animation. I have a script where my arms move along with the camera for better aiming and it is more realistic, but this causes the tool to not follow my arms. How can i fix this? [I use Motor6Ds for welding]
The Issue:
The Code that makes the arms follow the camera:
--Player
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Torso = Character:WaitForChild("Torso")
--Events
local UpdateFollow = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("UpdateToolFollow")
--Folder
local CharacterStatistics = Player.Character:WaitForChild("CharacterStatistics")
--Values
local Dead = false
Character:WaitForChild("Humanoid").HealthChanged:Connect(function(NewHp)
if NewHp <= 0 and not Dead then
Dead = true
game:GetService("RunService"):UnbindFromRenderStep("UpdateToolFollow")
end
end)
local Counter = 0
local CurrentCamera = workspace.CurrentCamera
local CurrentPos = CFrame.new()
local RS = Torso["Right Shoulder"].C0
local LS = Torso["Left Shoulder"].C0
game:GetService("RunService"):BindToRenderStep("UpdateToolFollow", Enum.RenderPriority.Camera.Value + 500, function(p2)
pcall(function()
Counter = Counter + 1
if Torso and RootPart then
local LookVector = RootPart.CFrame:toObjectSpace(CurrentCamera.CFrame).LookVector
if Character:FindFirstChildOfClass("Tool") then
Torso["Right Shoulder"].C0 = Torso["Right Shoulder"].C0:Lerp(CFrame.new(1, 0.5, 0) * CFrame.Angles(math.asin(LookVector.y), 1.55, 0), 0.2)
Torso["Left Shoulder"].C0 = Torso["Left Shoulder"].C0:Lerp(CFrame.new(-1, 0.5, 0) * CFrame.Angles(math.asin(LookVector.y), -1.55, 0), 0.2)
else
Torso["Right Shoulder"].C0 = RS
Torso["Left Shoulder"].C0 = LS
end
for Index, NewPlayer in pairs(game:GetService("Players"):GetPlayers()) do
if NewPlayer ~= Player then
if NewPlayer.Character then
pcall(function()
if NewPlayer.Character:FindFirstChild("Torso") then
local NewTorso = NewPlayer.Character:WaitForChild("Torso")
local NewCharacterStatistics = NewPlayer.Character:WaitForChild("CharacterStatistics")
local NewRS = NewCharacterStatistics:WaitForChild("Offset"):WaitForChild("RSPos").Value
local NewLS = NewCharacterStatistics:WaitForChild("Offset"):WaitForChild("LSPos").Value
NewTorso["Right Shoulder"].C0 = NewTorso["Right Shoulder"].C0:Lerp(NewRS, 0.2)
NewTorso["Left Shoulder"].C0 = NewTorso["Left Shoulder"].C0:Lerp(NewLS, 0.2)
end
end)
end
end
end
if Counter >= 3 then
Counter = 0
if Character:FindFirstChildOfClass("Tool") then
UpdateFollow:FireServer(Torso["Right Shoulder"].C0:Lerp(CFrame.new(1, 0.5, 0) * CFrame.Angles(math.asin(LookVector.y), 1.55, 0), 0.2), Torso["Left Shoulder"].C0:Lerp(CFrame.new(-1, 0.5, 0) * CFrame.Angles(math.asin(LookVector.y), -1.55, 0), 0.2))
else
UpdateFollow:FireServer(RS, LS)
end
end
end
end)
end)
The server only updates values to get other players’ arm positions and replicate them on my own client.