I have all my MeshParts stored in ServerStorage.
When I need a specific part (in LocalScript), I call a RemoteFunction:
local partReplicatedStorage = ReplicatedStorage:WaitForChild("RemoteFunction"):InvokeServer(partName)
In Server, if it is the FIRST TIME the MeshPart is requested, the script puts it in ReplicatedStorage:
local function LoadObject(player, partName)
local part = game.ReplicatedStorage:FindFirstChild(partName)
if not part then -- if not found in ReplicatedStorage...
part = game.ServerStorage:FindFirstChild(partName)
if part then part.Parent = game.ReplicatedStorage end -- puts the part in ReplicatedStorage
end
return part
end
ReplicatedStorage:WaitForChild("RemoteFunction").OnServerInvoke = LoadObject
It works ok, but when I call it inside a BindToRenderStep function, it’s taking almost 5 frames to return the valid object inside ReplicatedStorage.
For example, inside my BindToRenderStep function (LocalScript), for each frame, I have this:
print("BEFORE InvokeServer")
local partReplicatedStorage = ReplicatedStorage:WaitForChild("RemoteFunction"):InvokeServer(partName)
print("AFTER InvokeServer")
In the example above, I’ll get AFTER InvokeServer
message only before the 5th frame…
BEFORE InvokeServer
BEFORE InvokeServer
BEFORE InvokeServer
BEFORE InvokeServer
BEFORE InvokeServer
AFTER InvokeServer
What can I do to force my BindToRenderStep function to wait until the object replicated from the server becomes available in ReplicatedStorage?