RemoteFunction not returning object in Local Server instance

There is a RemoteFunction in ReplicatedStorage
In ServerScriptService:

game.ReplicatedStorage.RemoteFunction.OnServerInvoke=function()
	return Instance.new("Part")
end

In StarterPlayerScripts:

print(game.ReplicatedStorage.RemoteFunction:InvokeServer())

It seems to have something to do with the object not being parented. Maybe it’s GC?

I don’t think it’s GC.

My guess is that objects that haven’t been parented yet are not replicated. You’re passing the client a reference to a part that, according to the client, doesn’t exist.

I might be wrong though.

Edit: Here’s a quick fix I tested out. This should replicate the part to the clients first:

game.ReplicatedStorage.RemoteFunction.OnServerInvoke=function()
	local part = Instance.new("Part")
	part.Parent = game.ReplicatedStorage
	part.Parent = nil
	return part
end
1 Like

I don’t like this. I have to parent an object made on the server before I’m allowed to send it to the client. It isn’t just Instance.new, it’s also Clone.

That part isn’t parented to somewhere so it replicates, thus doesn’t exist on the client. If you send a reference of something and the receiver doesn’t know about it, it becomes nil.

Why are you even doing this?

The client is creating and copying objects. New objects have to be made on the server and sent to the client so they exist on the server. Changes are made on the client and signaled to the server to verify whether the client is allowed to make those changes and then make the changes on the server.

1 Like

Similar post:
http://devforum.roblox.com/t/replicating-orphaned-instances-via-remoteevents-remotefunctions/15007