Is this a good way to replicate to all clients?

So this is how it works

Trigger(LocalScript) > Checker(ServerScript) > Replicate(LocalScript)

so what this basically does is when I press F then it will fire a remoteEvent which will then be handled by the server then the server will fireallClient then the Replicate(LOcalScript) will create a part so a part will be created for the screen of players.

SCRIPT SAMPLE

Trigger(Local Script)

local function onTrigger()
  RemoteEvent1:FireServer()
end

Checker(Server Script)

function onRemoteEvent1()
  RemoteEvent2:FireAllClient()
end

Replicator(Local Script)

function onRemoteEvent2()
     Instance.new("Part",workspace)
end

Why not let the server create the part?

  • It has a delay so what I do is when the player triggers the Trigger script then it will first create a part for him before telling the server to create parts for all players so the player wouldnt know its delayed.

Im asking because I want to know if theres a better way or if this would cause lag.

2 Likes

This is usually the way that I do it in all of my games, and if you’re spawning a physics-based object like Parts, having them simulated on the client instead of on the server allows for less lag. You will have to implement some sanity checks and more.

will

for i = 1,10,1 do
  RemoteEvent1:FireServer()
end

be fine?

This will work completely fine, and I have tried it before.

Hey, here’s a tip. But you can simply use the same RemoteEvent twice; no need for 2 of them, like so:
Trigger (Local Script)

local function onTrigger()
    RemoteEvent:FireServer()
end

Checker (Server Script)

function onRemoteEvent()
    RemoteEvent:FireAllClients()
end

RemoteEvent.OnServerEvent:Connect(onRemoteEvent)

Replicator (Local Script)

function onRemoteEvent()
    Instance.new("Part", workspace)
end

RemoteEvent.OnClientEvent:Connect(onRemoteEvent)
2 Likes

It’s just not the server lagging, you used the parent argument which causes it to become more slower, i don’t know much what causes this but i have read that every part is memory block and something that relates to the changing of bytes in the memory block causing some little delay on the code.

So not only the server is lagging, the way you use Instance.new() also makes it more laggier and more delayed, read this post.

1 Like

I’d reccomend you to run that loop on the server, as now it has to run on clientA, then get recieved on the server at pretty much the same time, and then all 10 of them will get replicated to the other clients.

Those functions were examples, and I do believe the OP doesn’t use the second argument, but if so, using the second argument is indeed bad.