Make BodyForces work clientwise

A problem I’ve noted is that to much information is sent over to the server…

I have a remote event called “Force” that I can fire to add a body force or a body velocity inside a part X seconds. BUT I do this a lot in the local script and I’ve tried using HeartBeat instead of render stepped but it didn’t help a lot, if I could find a way to skip firing a remote event this would make the game less demanding for your computer power. And I’m thinking if there’s a way to make a force inside a client script effect a server part, If anyone has an idea how to please comment on this!

If a player has network ownership of the Part the physics will be calculated by them but still replicated to the server for everyone else to see without the need to use RemoteEvents

This does mean that they’ll have the power to move the part wherever they please if they’re an exploiter, so you’ll still need to check the part’s position on the server to make sure nothing too abnormal is happening

I don’t understand how I would do that, could you give me a more detailed explanation?

I remember this issue from way back and encountered the same thing. I solved it by treating it as I would a projectile in a very similar scenario. So you’d want to find a start and end goal. Get the relative path between. Visually calculate the object moving on the client and use the server to monitor the path between. This way, if the object somehow manages to out-of-bounds the path, it’s easy to detect whether or not this should happen.

If this is more than one object (like a projectile), I usually only render things that the client can see relative to other clients via a radius. It saves potential performance issues and no one really cares about things they can’t see.

1 Like

I’ve found a solution but sadly not clientwise and its to instead do the calculations inside the server which means I skip firing a remote event every frame, Sanjay has a good point and for anyone reading you could do what he did but for me it was impossible to get body forces to work inside clients but still simulate physics. Thank you Sanjay and JohhnyLegoKing for spending your time to help me

1 Like

You can set the network owner of a Part by using the :SetNetworkOwner() method which takes either a Player or nil (nil is equivalent to the server in this case) as its argument. The method will only work when used inside of a server Script though

Ive done research but somehow I still don’t understand how I could use this for physics, could you explain code wise?

When the player fires the object you’ll need to use a RemoteEvent to send a signal to the object in order to be able to use SetNetworkOwner, although you won’t be able to do this if the object is being created on the client

Well that means this is a bad solution to the problem since I have to fire a remote event every frame :man_facepalming:

You only need to fire the remote once when the part is created to change the network owner, there’s no need to fire it inside of a loop

Plus if the part is being created in a server script there isn’t a need to use RemoteEvents at all, you can just set the network owner there

Hmmm… I think I understand…

So the solution is to set the part there physics are involved to the network owner and then I can add body forces inside that part in the client to affect it?

1 Like

Yes, that’s what you need to do. Then the body forces will be handled by the client instead of the server

Although I do notice when I try adding forces in the server side it bugs out a bit, is there a way to fix that?

Edit: sometimes I will use forces in the server so that’s the reason i’m wondering

Since the client will be the network owner, I think creating the body forces in a LocalScript and parenting them to the part it should still start to move and any jittering or stuttering might no longer be a problem

Ok thank you so much! Have a great day

1 Like

Hmmm… Its still acting weird

Ok this is weird, the jittering effect is caused by the server view of the player being REALLY REALLY laggy. This is something I have to keep myself away from since the whole game relies on physics

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.