Hello, I’m making guns right now and I just implemented a script that gets your arms and head to move with the camera. I’m using a renderstepped function and save the original default C0 values before it starts, and then set the player’s C0s back to the default values once the tool is unequipped. I just don’t know how to smoothly transition or lerp the C0s back to the default value without it overwriting because of the function
Here’s the script.
plr = game.Players.LocalPlayer;
repeat
wait()
until plr.Character
char = plr.Character
m = plr:GetMouse()
local IsEquipped = false
local origRightS = char:WaitForChild("Torso"):WaitForChild("Right Shoulder").C0
local origLeftS = char:WaitForChild("Torso"):WaitForChild("Left Shoulder").C0
local origNeck = char:WaitForChild("Torso"):WaitForChild("Neck").C0
local c = game.Workspace.CurrentCamera
game:GetService("RunService").RenderStepped:Connect(function()
if IsEquipped then
char.Torso["Right Shoulder"].C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y), 1.55, 0)
char.Torso["Left Shoulder"].C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y), -1.55, 0)
char.Torso["Neck"].C0 = CFrame.new(0, 1, 0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y) + 1.55, 3.15, 0)
else -- Here is where the lerping/tweening should happen, it sets the C0's back to the default ones
char.Torso["Right Shoulder"].C0 = origRightS
char.Torso["Left Shoulder"].C0 = origLeftS
char.Torso["Neck"].C0 = origNeck
end
end)
script.Parent.Equipped:Connect(function()
IsEquipped = true
end)
script.Parent.Unequipped:Connect(function()
IsEquipped = false
end)