Rotating a character's Waist to match the Camera's LookVector

I have a script that constantly updates the player’s Waist.C0 to the position of the Camera’s CFrame.LookVector.Y. It works perfectly on the client, but how would I get it to replicate to the server so that other players can see the changes? I’ve tried combining :FireServer() with RunService:RenderStepped() to pass the camera’s current LookVector position to the server, but this method causes excess lag. Is there a simpler way to get the changes to replicate, without constantly calling :FireServer()?

7 Likes

That’s probably going to be your best bet. Though, rather than running it every render step, you can update it every time the Camera’s CFrame value changes instead. That will probably reduce the lag dramatically.

7 Likes

Does Roblox’s character not automatically replicate changes across, please, correct me if I’m wrong!

Thanks for the reply, I’ll give this a try right now.

To answer your replication issue, you can always just use a RemoteEvent and send the angle to the server and then back to all the players and update it. Probably want to interpolate that as well so it’ll be a smooth transition.

2 Likes

Quite a bit. Remember that the player has networking ownership over their character. Clients that have network control over parts can edit them as they please and changes will replicate.

That’s what I said earlier… I thought I was invisible!

i only read your first sentence :joy:

My bad. Either way, yeah, most things replicate from a character. Not all, but most.

1 Like

Here’s what I do to get this effect:

LocalScript:

Loop using a function bound to RenderStepped.

Check if the amount of time since the last loop exceeds a set time, e.g 0.1s. To make sure lots of RemoteEvents aren’t fired in a second.

Check if the look direction of the camera has changed from the last loop. This is to further cut down on unnecessary network usage.

Send an event to the server, with the parameter of the new direction.

Server:

Add a BodyPosition to the workspace.

To quote EgoMoose:

(Recommend reading this tutorial to help with your problem, too! He also provides sample code, which is great.)

You can then change the position of the BodyPosition whenever the remote event fires. In a loop, apply the BodyPositions rotation to the Waist.C0 and wallah!

A seemingly smooth system, that doesn’t kill the network, with a little, unnoticeable delay.

I hope I helped :smiley:

1 Like

Only physics-related properties are replicated when you have Network Ownership.

1 Like

Thanks man, I’m about to try out this method right now.

1 Like