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

Are there better ways to replicate local values/properties to other clients? (FilteringEnabled)

Asked by 8 years ago

Background Info

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.

Strategy

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 RemoteEvent, 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 RemoteEvent's FireClient:().

Example

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.

Answer this question