Hello! I have been making a FPS framework and I have encountered this problem. If I use Stepped, Heartbeat or a while loop for my Server Handler, the gun seems to lag behind while the player is moving. RenderStepped works fine but it can only be used in local scripts. How can I fix this? Here's my code:
local RS = game:GetService("ReplicatedStorage") local Run= game:GetService("RunService") local UIS = game:GetService("UserInputService") local Tservice = game:GetService("TweenService") local players = game:GetService("Players") local MainCframe = CFrame.new(0.8,1,-0.7) local function Equip(cam, primary) for i, player in pairs(players:GetPlayers()) do local GunClone = RS:WaitForChild("GunModels").Server.M4A1:Clone() local character = player.Character or player.CharacterAdded:Wait() character["Left Arm"].Transparency = 1 character["Right Arm"].Transparency = 1 GunClone.Parent = character Run.Heartbeat:Connect(function() GunClone:SetPrimaryPartCFrame(character.Torso.CFrame * MainCframe) end) end end RS:WaitForChild("Events").Equip.OnServerEvent:Connect(Equip)
It is not finished though.
Thing's I tried:
Searching online - I did not find anything helpful, Trying to use Bind to render stepped - I failed because I have no idea to use it.
There is no server-sided equivalent to RenderStepped (now called PreRender). RenderStepped fires every frame before rendering, and the server does not render anything, which is why it's client-sided in the first place.
Most people use RemoteEvents connected to RenderStepped to bypass this, like so:
-- goes in a local script game:GetService("RunService").RenderStepped:Connect(function() RemoteEvent:FireServer(arg1, arg2...) end) -- goes in a server script RemoteEvent.OnServerEvent:Connect(function(player, arg1, arg2...) -- first argument is always the player that fires the event -- do stuff end)
Read the documentation on RunService here and the documentation on RemoteEvents.