Query self.Part via remote event

I’ve created a part on the server via a Module Script and I wish to send it from server to the client. I keep getting nil and I don’t think I can send self.Part via a remote event. How can I do this?

2 Likes

You’ll need to set the part’s parent on the server-side first before sending it to the client, the client needs to be able to “see” the part for it to not be nil, even if it was created on the server

1 Like

The module was called from the server? I can’t do that in the module?

Could you share how the Script portion on how you create your part, and the LocalScript used to receive the RemoteEvent?

It is possible to set an Instance’s parent within a module that was required by a server-side script


@Workindad01 Here’s a test file that explains what I meant in my original comment:

ModulePartParentExample.rbxl (54.4 KB)

The scripts are:

  • A LocalScript inside of StarterPlayerScripts
  • Two server Scripts inside of ServerScriptService, each with their own module

I’ve just changed wait time to a bigger number. You should add task.wait to your script, because replication of a part from server-to-client takes time.
image

But the scripts in the example file are using task.wait (except for the LocalScript, which doesn’t require it to function as intended for the example. I did test it myself to verify this), and waiting for 1 second before firing the RemoteEvent?

I don’t know why my suggestions are being misinterpreted to this extent, so I think it would be best that I’ll leave and let other people handle this issue

Also in my defense, the Animation Spoofer is not something present in the test file I provided, so that could be interfering with your results

you can’t send Instance that isn’t visible to client, you need to parent it to workspace or else to do it, but in this case, it might be that OOP objects have problems with remotes, try to simply send name or smth and get it on client

Note: i forgot to add that it might be some weird roblox engine bug, try to send remote not inside object but after it’s returning like this:

local newBall = Ball.new()

remote:FireAllClients(newBall.Ball)
1 Like

You’re on to something: If the OOP object uses a metatable, the metatable is lost when sent through a RemoteEvent or RemoteFunction:

1 Like

yea, you’re right, but sometimes inside object creation function there is weird behavior that instance is not present yet because table is not returned or smth

1 Like

I’ve been thinking about what data to send. Since the Module is in OOP I don’t think I can pass self through to the client via a remote event. The idea is to secure the data on the serverside and pass only what’s needed to create the object on the client so that only the client can see the parts they created. With that in mind I was thinking about passing a table of data but idk how to get that data with the constructor the way it is. Here is the table to pass, will this pass correctly?

1 Like

It should be ok, since the table is strictly a dictionary (mixed tables are also unable to be sent) and its contents aren’t inherited from a metatable :slight_smile::+1:

Although it’s important to note that, in the table indexing section Remote Events and Callbacks article, there’s a warning that states that it’s recommended to avoid having nil as a value of any index:

So if any of the table’s value is nil before being sent, it could explain why you’re experiencing the issue, so I recommend checking to make sure