Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Lag with moving parts with RenderStepped?

Asked by 6 years ago
Edited 6 years ago

Hey guys, so I created a script, shown below, that changes the character's neck Motor6D's CFrame so that it rotates the head according to the player's mouse position every renderstep. It works great and all, except the movement has a slight lag to it. As you may have noticed, since I am using Filtering Enabled, I was wondering if calling the server every renderstep was what was causing the problem, or if it was something else. I would really appreciate it If someone could help me in finding a solution that will either eliminate or greatly reduce this lag. Thanks in advance

--All variables defined above

--Client
runService.RenderStepped:connect(function()
    local character = player.Character
    local torso = character:FindFirstChild("Torso")
    local neck = torso:FindFirstChild("Neck")
    if torso and neck then
        cameraEvent:FireServer(x, y, neck) --Move neck (FE)
    end
end)

--Server
cameraEvent.OnServerEvent:connect(function(player, x, y, neck)
    neck.C0 = CFrame.new(0,2,0) * CFrame.Angles(y + 0.1,0,0) --Head simulation
end)

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
6 years ago

You cannot simply edit the welds from the server while simultaneously editing them from the client. This is because your server changes are then mirrored back to the client that called it in the first place.

There are several ways around this:

  1. ONLY have the server edit welds. The downside of this is that there is a delay between what the neck should look like vs what it actually looks like due to latency between the client and the server.

  2. ONLY have clients edit welds. Whenever FireServer is called from the client, the server just passes these back to all the clients (except the one that called FireServer) with FireAllClients. The clients will have to handle the neck welds locally. This ensures that changes to the neck are instantly visible to the client. However, the downside is that server hitboxes will be inconsistent with what the character looks like to everyone else.

  3. Do what you're doing right now, but create a fake head that the client will manipulate locally, while turning the original head invisible for the client. The server will still handle neck welds as normal. I would personally recommend this choice if you're OK with cloning heads.

(As a sidenote, throttle how often you call FireServer. Calling that 60 times per second is waaaay to fast. You'll be reaching your bandwidth limit of 50kbps quickly. If you find that the neck is choppily updated, use CFrame:Tween)

Ad

Answer this question