Need help in preventing FPS lag

I was learning how to make an FPS system follow this tutorial:

Well, it works and the guy who makes the tutorial have really comprehensible code but there are some issues that is worth to mention. Anyway, to be specific, he doesn’t replicate it to the server for the other players can see that i’m holding a gun and i noticed this when i switched to server mode. That is why i spent the entire night and this morning to solve this limitation(not exactly an issue), the reason it takes this much time is because i haven’t figured out that the primarypart just fell of the map countless times and i’ve succeeded to solve it. However, there is another problem


As you can see, when i tried to use the remote event to replicate the coordinate follow client’s camera but it’s just so lag and i do not want my player to experience this. Is there any way to prevent this limitation?
Client script:

repeat

wait()

until game:IsLoaded()

local player = game:GetService("Players").LocalPlayer

local mouse = player:GetMouse()

player.CameraMode = Enum.CameraMode.LockFirstPerson

local weapon = game:GetService("ReplicatedStorage").AK47

local runservice = game:GetService("RunService")

local aiming = false

local aimCFrame = CFrame.new()

local enable = game:GetService("UserInputService")

enable.MouseIconEnabled = false

runservice.RenderStepped:Connect(function(dt)

local turn = workspace.CurrentCamera.CFrame*CFrame.new(0.7,-1,-0.67)*aimCFrame

game:GetService("ReplicatedStorage").pose:FireServer(turn)

if aiming then

aimCFrame = aimCFrame:Lerp(CFrame.new(-0.7,0.3,1.5),0.1)

else

aimCFrame = aimCFrame:Lerp(CFrame.new(),0.1)

end

end)

mouse.Button2Up:Connect(function()

aiming = false

end)

mouse.Button2Down:Connect(function()

aiming = true

end)

Server script:

local weapon = game:GetService("ReplicatedStorage").AK47:Clone()

weapon.Parent = workspace

local handle = weapon.Handle

handle.Anchored = true

game:GetService("ReplicatedStorage").pose.OnServerEvent:Connect(function(player,turn)

weapon:SetPrimaryPartCFrame(turn)

end)

Appreciate everyone’s support :))

1 Like

Update and render the weapon in the client, if you want others to see it, send 1 event to the server with :FireServer(), clone the weapon in the server and weld and parent it to the right hand of the character

2 Likes

Well, i think there is an issue, the client will see two guns at the same time so is there any more suggestions?

When you are in 1st person, anything inside the player’s character will be invisible so its safe to say its ok to render the gun itself in the client(you)

1 Like

oh, well then i couldn’t use the script from above, i have to switch to use tools from now to let it handle using the right hand

you can, just remove game:GetService("ReplicatedStorage").pose:FireServer(turn)
and replace it with
weapon:SetPrimaryPartCFrame(turn), make it below the if aiming statement

1 Like

What do you mean? the server still can’t see it

try researching this tutorial, most the things I said came from here Making an FPS framework: 2020 edition: part 2 - Resources / Community Tutorials - DevForum | Roblox

2 Likes