An Issue with Remote Function

In my inventory system, I am trying to get what player has in his/her inventory by a RemoteFunction from a client to the server but I am getting two errors which tell me that I am not sending a string.
My details:
image
My Code:

Client Side:

local function setCateItems(plyr, categ)
local objectsOfCateg = getPlayerInventoryfunction:InvokeServer(plyr, categ)
clearList()
for i, object in pairs(objectsOfCateg) do
	local cloneItem = object:Clone()
	table.insert(objectsOfCateg, cloneItem)
	local cloneTemplate = template:Clone()
	cloneTemplate.Name = object.Name
	cloneTemplate.Amount.Text = object.Cost.Value
	cloneTemplate.Background.ImageColor3 = categoriesColors[categ.Name].CellBackground
	cloneTemplate.Visible = true
	cloneTemplate.Parent = inventoryGUI.ItemsFrame
end
end

Server Side:

getPlayerInventoryfunction.OnServerInvoke = function(plyr, categ)

return players[plyr].Inventory[categ.Name]:GetChildren()

end

Player when invoking the remote function
image

You need to fix this area of the code, try this:

getPlayerInventoryfunction.OnServerInvoke = function(plyr, categ)

return players[plyr.Name].Inventory[categ.Name]:GetChildren()

end

When parsing an instance using brackets you need to use a string, and since the first argument returned by RemoteFunctions/RemoteEvents is the player instance, you need to ensure that you are referencing plyr.Name as opposed to simply “plyr”.


Edit:
I also noticed upon writing that you have another small slip up here:

Player is already an argument, so essentially what you are doing is registering the OnServerInvoke arguments as Plyr, Plyr and since you aren’t identifying a third argument “categ” is never registered.

Try using this as well:
getPlayerInventoryfunction:InvokeServer(categ)

2 Likes