Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the best way to replicate client-controlled values to other clients? (FilteringEnabled)

Asked by 8 years ago

Just started to work with FilteringEnabled. Everything works fine and its a great feature. It helped me A LOT by showing me how a proper game should be organized.

Back to the question, I figured that the values would just have to be send to the server, and the server would replicate them, but this allows both the client and the server to edit the same values at the same time. Since the server has a slight delay, some old values were being replicated to the client who already has control of these values. There's no need to replicate to the client with the values.

Now, I've got a local script under the character that gathers the wanted values in a list, and detects the Instance.Changed event of the values.

When Instance.Changed is fired, the value(s) are handed to the server via RemoteFunction, and a server script performs FireClient:() for all the other players except the one who sent the values.

Then another local script under the player replicates the values sent by the RemoteFunction's FireClient:().

So from the local script in the character:

ReplicatedStorage.Remote:FireServer(ValueObject,ValueName,Value)

To the server:

ReplicatedStorage.Remote.OnServerEvent:connect(function(Player,ValueObject,ValueName,Value)
for _,p in pairs(Players:GetPlayers()) do if Player~=p then
ReplicatedStorage.Remote:FireClient(p,ValueObject,ValueName,Value)
end end
end)

To the other clients:

ReplicatedStorage.Remote.OnClientEvent:connect(function(vo,vn,v)
vo[vn]=v
end)

Now, I only have the other clients replicate the values (instead of just letting the server do it) so that the client which sent the values to be replicated doesn't get back his/her own values. If this happens, there could be incorrect values since the both the client and the server would be setting the same values.

It works this way, but I feel as if there is a simpler way. I'm fairly new to RemoteEvents and RemoteFunctions.

Thanks in advance.

0
Please use code blocks. LateralLace 297 — 8y
0
Sorry bout that. JayManLive 15 — 8y

Answer this question