Does anyone know why this is so laggy?

I am trying to make FPS-styled arms, but they are very laggy. I have an R15 rig that I weld to the player’s head locally, and each render stepped, I change the C0 of the weld so that the arms stay on the player’s screen. Does anyone have any idea why it is so laggy?

local Inst_rep = game.Workspace.Rep:Clone() -- the R15 rig that I weld (I deleted its legs)
local Inst_w = Instance.new("Weld")
Inst_w.Part0 = Inst_character.Head
Inst_w.Part1 = Inst_rep.Head
Inst_w.Parent = Inst_character.Head

Inst_rep.Parent = game.Workspace

RunService.RenderStepped:Connect(function()

	Inst_w.C0 = Inst_character.Head.CFrame:Inverse()*(Inst_cam.CFrame)*CFrame.new(0,0,-1)

end)

1 Like

because you are constantly setting the cframe of the object that can fire a tens of times per second

Are you trying to lock the player in first person mode? If so, you can just do this:

player.CameraMode = Enum.CameraMode.LockFirstPerson

You should do this in a localscript and put it in playerstarterscripts, or you can connect the playerAdded event and fire this code when a player is added

Reference to player.CameraMode

— EDIT —
Oh wait I missed that you want arms on the screen -_-

Try setting workspace.Camera.CameraType = Enum.CameraType.Scriptable

The camera is fine; my goal is to make the arm movements smoother. I don’t know why they are so laggy.

I think the arms are laggy because the camera is lagging behind. Did you try my script anyways?

The math isn’t that complex though?

Just setting the camera to scriptable means that I need to make my own camera script, which doesn’t sound like a whole lot of fun to me… Also, I’m not how making a custom camera script would solve the issue of the camera being too slow.

well there are a ton of variables in it

You might need to interpolate between the old and new values.

I just found a video. I haven’t watched it though, but I think it might help

— EDIT —
The video just makes the arms untransparent. You can then lock the person in first player mode as I suggested in one of my posts above
— Another EDIT —
I found some info about LocalTransparencyModifier, the one they used in the video

1 Like

Interpolation might be a bit iffy since I’m changing the C0 every RenderStepped. I will try though.
Edit: Interpolation kinda yields the same results. Good idea though.

I’m going on a limb and guessing you might be able to curve some of the issues by using the DT parameter to keep track of time.
Does the same issue occur if you use something like Heartbeat instead?

As a side note you can do

Inst_w.C0 = Inst_character.Head.CFrame:toObjectSpace(Inst_cam.CFrame)*CFrame.new(0,0,-1)

If you want something a little more legible. (Assuming you meant to do (CFrame:Inverse()*CFrame) * CFrame
Otherwise move the parenthesis appropriately :slight_smile:
Might be slightly faster too since it gets calculated in 1 func call and 1 multiplication instead of 1 func call and 2 multiplications

Interestingly, when I use the Heartbeat or Stepped events, I get flung as soon as I join the server. Only RenderStepped doesn’t fling me.

Another thing to do is set the CFrame of the Head of the rig to the camera’s CFrame. This involves less math, and the article where I found it is here: The First Person Element Of A First Person Shooter

You might be getting flung because you only removed the model’s legs so it can still collide with the real character.

Try welding to the HumanoidRootPart instead as the head Motor6D’s values depend on the character’s animations. That might be the cause of your issues.