Get Is Not Available

21:00:45.038 - OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available

Server
local tools = {}

game.ReplicatedStorage.InventoryCheck.OnServerInvoke(function(player)
  if game.ServerStorage.Inventories:FindFirstChild(player.Name) then
  local inv = game.ServerStorage.Inventories[player.Name]

  for _, item in pairs (inv:GetChildren()) do
    if item:IsA("Tool") or item:IsA("Model") then
      table.insert(tools, item.Name)
    end
  end

  return tools

end

end)

Client

local playerName = player.Name
local replicatedStorage = game:GetService("ReplicatedStorage")--Defines replicated storage

coroutine.resume(coroutine.create(function()
  while wait() do
    local check_inv = replicatedStorage:WaitForChild("InventoryCheck")

    for _, v in pairs (check_inv:InvokeServer())do
      if v == script.Parent.Parent then
        script.Parent.Visible = false

        break
      end
    end

  end
end))

local success--Variable

script.Parent.MouseButton1Click:Connect(function()
	
	success = false--Makes success false
	if selectedItem.Value ~= nil then--If the value isn't equal to nil
		selectedItem.Value = script.Parent.Parent.Name
		print(selectedItem.Value)
		success = replicatedStorage.CheckSale:InvokeServer(selectedItem.Value)--Make a request to the remote function
	end
	
	if success then
		print("Purchased!")
		
	else
			
			print("Purchase Failed!")
	end
	
end)

Basically you’re trying to call OnServerInvoke, but as the exception implies, there is no getter for this, only a setter. You likely meant to do:

function game.ReplicatedStorage.InventoryCheck.OnServerInvoke(player)
    local tools = { }

    if game.ServerStorage.Inventories:FindFirstChild(player.Name) then
        local inv = game.ServerStorage.Inventories[player.Name]
        
        for _, item in pairs (inv:GetChildren()) do
            if item:IsA("Tool") or item:IsA("Model") then
                table.insert(tools, item.Name)
            end
        end
    end
    return tools
end

Remember that

function a.b() -- Writing to b, not reading from b

end

is syntax sugar for

a.b = function() -- Writing to b, not reading from b

end

So you can do the latter if you wish.

1 Like

Could you show what is happening on the client script? It seems that something fails to retrieve in the client side otherthan the server side script.

Oh, I see why it fails. Tools should be located in ReplicatedStorage, not ServerStorage. Clients are unable to see what’s on ServerStorage. In case you’re wondering why, client scripts cannot see what’s on server services (ServerScriptService & ServerStorage).

Isn’t that why you need Remote Function(in this case)?

If you prefer using RemoteFunction to get tools, sure, but it isn’t recommended to. Possibly the connection to the server would result in an error if it took too long to retrieve back the data or there wasn’t a OnServerInvoke function.

Instead, I recommend doing ReplicatedStorage:FindFirstChild("Instance") or ReplicatedStorage:WaitForChild("Instance", 30). Connect it to a variable. Then, you could get the Instance. Like this code below:

local obj = ReplicatedStorage:FindFirstChild("Instance") or ReplicatedStorage:WaitForChild("Instance", 30)

if obj then
 -- Run the function/event/code
end