I want to replicate a NumberValue (or any other value) real-time from the client to the server. I would like to do this preferably without firing hundreds of remotes per second.
For example, Roblox automatically replicates the player position to the server real-time! How would I create something that does basically the same thing?
What is the issue?
Right now I’m firing an event from the client with a CFrame value around ~5 times a second which is then handled on the server. With 20 player servers this becomes 100 CFrame values being sent per second. I don’t know much about networking but this seems like it could lag a bit.
What solutions have you tried so far?
RemoteEvents
Putting a value in ReplicatedStorage (disappointingly doesn’t replicate from client)
I’m happy with any method, even if it’s some strange trick like parenting a value to the players character or something. (i would be laughing if what i just used as an example actually worked)
Not exactly sure what your value is for but instead of sending it every 5 seconds have you tried only firing when the value has been changed? If you have tried this and there’s no change I’ll look around for some more solutions.
I think that would be the only way to do so(firing from a remote event)
but to make it look immediate I would change it on the client first
also I think Roblox uses network ownership to make replicate positions faster
I’m afraid this isn’t possible for regular game scripts. Roblox can do it in engine/game scripts because… they’re Roblox, ahah. The only reliable way to transmit this data would be thorough remote events (that I’m aware of).
Unless you just want a server script to use a for loop and check all of the values at once and update them? It might be easier to just keep things as is but that might be something you look into.
Why are you needing to fire it five times a second? Is it for an animation or something? Is proper timing crucial for what you are trying to achieve? Otherwise, it is rather overkill and could even make things worse than they need to be. I would only try to fire an event from client to the server only if that value has changed like what @Jacko_Korbius has said.
While this is only a speculation (so take this with a grain of salt), but usually the server doesn’t have to render graphics as it hides within the depths of the server towers at the Roblox Headquarters (or some other location). However, the client has to (as that is the side of the player, where graphics are necessary to even play your game). Due to this, the server could focus on handling the server logic, including accepting 100 event fires per second with little to no problem. The only exception is if you are testing the Server-Client sides on your computer, where the server has a graphical representation to make it more user-friendly and useful for the programmer.
With that said, I still recommend what I said earlier as, again, it is a waste of computational energy to spam the value of a variable 5 times a second when all you need to do is to only send that value to server when it changes in the client.