Need help accessing created part from server

Hello! I want to instance a part on the server and access it on the client.
I tried this:

-- Server
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function()
      local Part = Instance.new()
      return Part
end
-- Client
local Part = game.ReplicatedStorage.RemoteFunction:InvokeServer()
print(Part) -- Prints nil for some reason

Yes, I’ve searched but had a hard time finding anything sorry.
When i get the part from the client, it’s nil for some reason.

1 Like

I believe you first need to create the Part’s properties, then parent them to the workspace? Try this:

-- Server
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function()
      local Part = Instance.new("Part")
      Part.Parent = workspace
      return Part
end
-- Client
local Part = game.ReplicatedStorage.RemoteFunction:InvokeServer()
print(Part) -- Prints nil for some reason
2 Likes

What do you mean access it? I’m unsure as to what you’re trying to accomplish.

1 Like

Hi, by accessing it I mean be able to get a reference to that part in the client. Idk how else to explain it sorry.

as jackscarlett said, you have to parent it to workspace (or somewhere else)
edit: also, as cristiano100 said, you must fill the first argument. i didnt see that mistake

You need to fill out the first arguement of the new() function, which if you wanted a part would be “Part”

 local Part = Instance.new()

Such as

Instance.new("Part")

It also needs to be parented somewhere the client can access it.

Hello! I solved my issue.
For future reference for other people:

-- Script i used
-- Server 
RemoteFunction.OnServerInvoke = function(player, Item)
     return Item:Clone()
end

-- Client

local Item = RemoteFunction:InvokeServer(Cake)

The issue was that I forgot the player argument existed lol so I tried cloning the player

1 Like