Need help with InvokeServer()

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to achieve the fact that when I invoke from the client to the server when the game loads, it returns without having to use wait().

  2. What is the issue? It always returns nil. I am cloning a object from ReplicatedStorage on the server and returning it to the client.


  1. What solutions have you tried so far? I’ve looked for many solutions and all I have seen it to add wait() statements before the return. This works, but can cause issues for lagging players and can return nil the odd time and I don’t want to have to have to use simple wait() statements to fix this.

I am trying to look for ways to return the function only when the cloned object exists on the client. I’ve tried game:IsLoaded too. If there is any way, even switching from using RemoteFunctions I’ll be happy.

Is the second image in a function?

The second image is inside of CreateClass.OnServerInvoke. It’s the server script.

I’m gonna wait until you realize that you put return in the wrong place or something.

The only way I can think of to explain this behavior: You are passing an instance over the server-client boundary, and since you are always receiving nil on the client, I believe Roblox isn’t letting that reference through.

I’m guessing you parenting newHandle to the character of the player who passed it right? Maybe the reference to that part is returned before the part is actually replicated to the client, which is why Roblox sends nil instead?

Note that if an invoked RemoteFunction creates an instance on the server, there is no guarantee that it exists on the client when the function returns. [1]

If you’re waiting for equippedHandle, it’s best if you would do:

repeat until equippedHandle

This is an unnecessary comment. Also, it will still return the object if I add a long wait() so that statement is false.

Also, for some reason it will return with the name of the object but not the actual object so this is some sort of band aid solution.

Since you know where the handle is going to be added, just declare the variable, invoke server, and then do a childAdded:Once() on the character and let the connected function set equipped handle to the newly added instance (make sure to check the name though)

This seems to work really well. Thank you.

1 Like