FPS System ServerSide

So im making a system where the gun faces the mouse position with Motor6ds but im curious if I should repeatedly fire a RemoteEvent to change the Motor6d of the Arm which I tried and it was pretty buggy,

RunService.RenderStepped:Connect(function()
      RemoteEvent:FireServer(...)
end)

I was thinking of NetworkOwnership but it wasnt possible on Motor6ds so is there any other ways I can make this into a ServerSide?

Just do it client side and have an animation serverside. No one needs to see. Just have a fake gun with fake arms that is cloned from somewhere when you equip it and use a bind to render stepped and cframe it to the camera. From there you can fine tune the positions to make it look good. With this solution you could even make it actually aim the gun on right click and get that smooth transition.

Additionally firing to the server 60 times a second is very recourse intensive and will create a TON of lag

that is if it doesnt crash or something…

you can fire the event every 0.2-0.5 seconds or so and lerp the previous value with the same time as the firing debounce, as far as I’m aware this doesn’t put a lot of pressure on the server as long as you set some local sanity check to optimize remote usage whenever possible.
as for the code you can do this

--Local Script
local MinY = 0.92 --//highest look angle 
local MaxY = 0.92 --//lowest look angle
local Previous
while wait(0.2) do	
    if not hum then return end	
    local look = mouse.Origin.lookVector.Y
    if Previous ~= look and look > -MinY and look < MaxY then
       remote:FireServer(look)
    end
    Previous = look --//making sure the client doesn't send multiple remotes with the same arguments
end
--Server Script
game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(plr, mousepoint)
   if mousepoint < -0.92 then 
      mousepoint = 0.92
   elseif mousepoint > 0.92 then
      mousepoint = -0.92
   end --//verifying the look angle incase the client bypassed the check
   local chr = plr.Character

   local torso = chr.Torso
   local Neck = torso.Neck
   local LeftShoulder = torso["Left Shoulder"]
   local RightShoulder = torso["Right Shoulder"]

   local RC0 = CFrame.new(1, .5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0) 
   local LC0 = CFrame.new(-1, .5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0) --//base C0 cframes for the left and right shoulder 

   local function TweenMotor(Motor, EndCF) 
      local prop = {C0 = EndCF}
      local info = TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) --//editable
      game:GetService("TweenService"):Create(Motor, info, prop):Play()
   end

   local look = CFrame.Angles(0, 0, math.asin(mousepoint))
   TweenMotor(RightShoulder, RC0 * look)
   TweenMotor(LeftShoulder, LC0 * look:inverse())
end)

which should move your arms up and down according to the direction of your mouse, of course do edit these to serve your intended purpose

1 Like