Cannot return a instance with a RemoteFunction

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

  1. What do you want to achieve? Keep it simple and clear!
    Return a instance.

  2. What is the issue? Include screenshots / videos if possible!
    Cannot return a instance and always get a nil

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    ive legit looked everywhere but i cant fix it

local maga = vrEvents.SpawnItem:InvokeServer(vrAssets.Assets.GunMags[mag])
events.SpawnItem.OnServerInvoke=function(player: Player,item: Instance)
	local clone = item:Clone()
	clone.Parent = workspace.Pickups
	return clone

When you transfer an object like this, it only transfers a reference to the object. If the object doesn’t exist on the client/server, it will be nil. You’ll need to rework this so that the objects are created on the server and let Roblox handle the automatic replication to the clients.

1 Like

It is created on the server, but how would I go around letting the client wait for the replication of the instance?

You can add the object to ReplicatedStorage (or a folder in it, to not clutter it up).

Forgot to hit reply, see above post.

It is in ReplicatedStorage (Where the vrAssets are).

In the client script, run game.ReplicatedStorage:WaitForChild("VR"):WaitForChild("Assets"):WaitForChild(...) at the beginning to make sure that they are replicated before asking the server.

I thought this wouldn’t fix it but now it is very close to being fixed so I think this is the solution.

Glad I could help! Let me know if you have any other issues.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.