How to sync up the client and the server

I am making a game with a ball, and to prevent lag, i am adding velocity to the ball to fire it on the client, before requesting it on the server. The issue is, the end result of where this ball ends up once it has slowed down is a few hundredths of a stud different on the client and the server after the shot. This is creating a few issues for me, especially a few shots down the line. Is there a way i can “set” the position of the ball on the client to be at the position of the ball on the server?

3 Likes

Uh, I can think of two things right now about this.

  1. You can move it on the client and fire the Vector3 through an RE and have the Server set the position of the ball to that Vector3
  2. You can set the client to be the NetworkOwner of the part then on the Server change the Velocity of the part then the client should calculate the part’s physics. Here’s an article about it; Network Ownership | Documentation - Roblox Creator Hub

(I suggest the 2nd method)

3 Likes

Im guessing method one would result in the ability to exploit, but would method 2 still be instant if the server first has to change the velocity?

1 Like
  1. Yes, the first method is insecure which is one of many reasons I suggested the second.
  2. What do you mean “instant”? Are you asking if it would delay? It would probably delay by less than a millisecond; luavm is very fast. Are you asking if the part would move instantly to that position as if a script had put it there instead of it being moved by velocity? The method I gave you should do move it normally with Velocity as if it were being pushed.
1 Like

if the client is the one who “fires” the ball, I would have to RE to the server? Or looking at the article, do i change the velocity on the client, and it will still “replicate” to the server even with FE because it is the owner?

1 Like

I think you would, but I’m not sure. If clients could change velocities any time they wanted exploiters would probably have a lot of power. Try it on the client first, then do the server I guess.

1 Like

cc @azahid1,

Both method 1 and method 2 would be just as exploitable, because the client having network ownership is basically the same as the client setting the position of the ball on the server, the only difference being that the client gains visual feedback on this action much quicker than a round-trip from client to server and back to client through remote events and replication.

1 Like

Thanks, ill give both a go and get back to you. Even if the exploiter had access just to a single ball, it wouldnt be too much of an issue for me anyway

2 Likes

What you could do, is have both the client and server fire the ball. The client would tell the server, than the server would see the result, then the client would tween their result to the server’s result. This method would prevent exploiting and help sync them both.

2 Likes

I don’t think so? If I’m not mistaken roblox automatically sets NetworkOwnerships to clients who are near, so if that was the case a lot of places would probably be filled with exploiters.

1 Like

This is true, but explicitly setting network ownership to the client will make that part always be owned by the client instead of just passing physics responsibilities to the server when the part is outside their .SimulationRadius. I think it said this in the network ownership page you linked as well.
The normal behavior is triggered by using Part:SetNetworkOwnershipAuto() by the way.

1 Like

Script is fast but how I understand it it will be delayed by internet speed

1 Like

Well yes, but Roblox servers are fast. You should only manually set the networkowner to clients during certain times, such as if they are shooting a bullet from a gun, or in this case, a ball from some sort of launcher.

2 Likes

Roblox server yes but if there come some exploiter with slow Wi-Fi slow internet and slow pc. In time when he is executing lua from exploit it can bug parts owned by him for seconds.

pinging you too since you also seem to have some questions regarding exploiters and networkownership @mistr88

I’ve thought a lot about this during my spare time, and I’ve also kind of been confused about exploiter’s control regarding NetworkOwnership. @zeuxcg 's description says he’s responsible for all things client, so let’s see if he can help.

1 Like

This is what I tried originally, but my question is, how do I know, on the client, what the position of the ball is on the server, if they are different. Do I use a local script, and set the position to what? Do I have to use a remote function or something?

I think just send info about direction,… via remote function to server and give it the motion on server

I tried exploiting on my own map while anti exploit system and everything client is exploitable but the exploit make also delay on client response and to put the ball on client side may more lag the server than unlug

Also it is deleteabele for client and now I don’t know if when he owns it it will also be deleted on server

Here, let me make a easier to read map:

  • Client sets velocity of ball
  • Client tells server through remote event to launch the ball (server does it server side)
  • Server launches the ball
  • Server waits for ball to stop, sends position to the client through a remote event
  • Client tweens their ball to the location sent by the server.

This method is the most secure way. It will make sure the client can not cheat, while giving the client instant feedback.

Another option is to set network ownership. This will give instant feedback, but the client can easily lie about the position.

A third option is to just set it from the server. This won’t give instant feedback, but it will still be secure.

7 Likes

Thanks, this is the bit I was stuck over.