Hello, I’m wondering how to handle grenade throws (or similar projectiles) properly. When my grenade is made on the server, it freezes for a brief moment in the air. When I try creating it locally and then inform the other clients that a grenade has been thrown, the physics don’t sync.
I’ve been searching the dev forum for quite a while now, and although I’ve found a lot of posts regarding this topic, I haven’t found any answers.
Is there a correct way to do this? To clarify: I’m not asking about how to make a grenade, but rather how to sync physics between all clients and the server without lag.
I think it would be better to fire to a server script (using a remote event) once the event that triggers the grenade throw is triggered (whether that be a mouse click or UIS or whatever) and then handle everything on the server so that the physics can be handled by the server. I dont know if doing it both on the server and client is hard or not but you don’t really need to do it on the client so stick with just the server.
at least that’s what I would do- good luck and I hope I helped in some way
Hey thanks for the reply, as mentioned in my post I did try that (sorry for being unclear), but it caused the grenade to clearly freeze in the air for a brief moment
Maybe in the server script try setting the network owner of the grenade, (if it’s a model set the primary parts network owner not the model) grenade:SetNetworkOwner(player)
You don’t need to do anything with that, just call it it should make it smoother, the network owner is the player unless on the server it’s automatically nil so set it to the player and it should work better I think
so no mater what there is always a delay when you send information over the internet
and the delay will be different for every player deepening on there ping
so the 2 options you have are
the server does the physics and all clients see a delay depending on there ping
one client does the physics and all other clients see a delay depending on there ping + the one clients ping because first the client sends the position to the server then the server sends that position to all other clients
if you want the client to do the physics you must set them as the network owner by default the network ownership is set to auto what auto means is who ever is standing closest to the object will have ownership but be warned as the network ownership changes from one player to the next the object might stutter and teleport a little
once a client has ownership of a object you can use a localscript to adjust the objects position and velocity
while this video is not about grenades it does show you how to have a car that is network owned by the client and the client can steer the car with no lag but the other clients will have a delay of the cars position
also as some extra information.
the position is not sent every frame over the network the clients will use the velocity of a object to fill in the gaps each frame and there is a small amount of tweening done when they recive the latest position over the internet