I'm making a gun, and decided to add animations and make the player's arms follow the mouse. I have a problem and a question.
Firstly, I'm having a weird problem, I have the gun, but when I duplicate it, the second one's "follow camera" system doesn't work.. Here's the code
local plr = game.Players.LocalPlayer repeat wait() until game.Players.LocalPlayer.Character local char1 = plr.Character local Anim = char1.Humanoid:LoadAnimation(script.Parent.Idle) local RightArm = char1.Torso["Right Shoulder"].C0 local LeftArm = char1.Torso["Left Shoulder"].C0 local Neck = char1.Torso["Neck"].C0 local ChangeVariable = false repeat wait() until game.Players.LocalPlayer.Character local char = plr.Character local m = plr:GetMouse() game["Run Service"].RenderStepped:Connect(function() if script.Parent.BoolEquipped.Value == true then local c = game.Workspace.CurrentCamera 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 local c = game.Workspace.CurrentCamera char.Torso["Right Shoulder"].C0 = RightArm char.Torso["Left Shoulder"].C0 = LeftArm char.Torso["Neck"].C0 = Neck end end) script.Parent.Unequipped:Connect(function() char.Torso["Right Shoulder"].C0 = CFrame.new(0,0,0) char.Torso["Left Shoulder"].C0 = CFrame.new(0,0,0) char.Torso["Neck"].C0 = CFrame.new(0,0,0) end) script.Parent.Equipped:Connect(function() Anim:Play() end) script.Parent.Unequipped:Connect(function() Anim:Stop() end)
I also have a question, does anyone know how can I make it so that the character's arms follow the mouse, but in a server script?
It's not recommended to use a remote event to fire the mouse position to server, but if you want to do so, fire the mouse position every 0.5 seconds so it won't take your performance by a lot. The only downsides is it will take more performance than using local script to control head movement instead of remoting it to the server, and the head movement won't be smooth