I set the CFrame of the viewmodel every frame with RunService.RenderStepped.
Visually, it is perfectly fine, but the problem is when I reference the CFrame of any basepart within the viewmodel in a script.
It is pretty difficult to explain, so this is what it looks like:
In the video, you can see that the move tool visuals lag behind when the gun moves in any way.
(Using the move tool was just to demonstrate the lag. The main problem with this is that bullets and laser sights also lag behind when moving.)
The code to position the viewmodel is essentially just this:
Mostly everything is attached to “Main” with WeldConstraints or Motor6Ds
The viewmodel itself is created on the server and is parented inside a folder inside the workspace when equipped. This is different from the more common way to do viewmodels, where it is created on the client and is a child of the camera. However, I have also tried this more common method and still had the same lag problem.
I am completely stumped and can not find any similar problems anywhere else. Any help is appreciated, thank you!
I’d look into using RunService:BindToRenderStep instead of RunService.RenderStepped, because it has an option to bind at a custom priority. Without seeing your scripts I’m guessing your loops for updating bullets or laser sights are running before your view model updates, causing them to be a frame behind.
use .Stepped instead of .RenderStepped because setting the cframe of the viewport before the physics simulation could cause inconsistencies with any parts or attachments connected to it
I tried some stuff with BindToRenderStep but I could not achieve a good result, although I have never used BindToRenderStep so I could be using it incorrectly.
But the bullet and laser sight code is not the problem. Everything lags behind the viewmodel. In the video, it shows how Roblox’s built-in move tool even lags behind.
The problem was actually not related to anything lagging behind the gun, it was something with my recoil code. I just got confused because Roblox’s move tool was lagging behind, but it actually just does that with everything.