I am attempting to create an inventory system where the client receiving a new item(at the moment a button click to simulate it) fires to the server, the server then checks for the item inside of a module script and then if the item exists the script will invoke a remote function which would update the inventory.
At the moment it doesn’t update the inventory as I’m setting up the basic framework of client-server relations. I’ve ran into an issue - the table won’t be passed through when I invoke the remote function to the client. For a more practical view, here’s the scripts:
The button - a local script that simulates an item being given to the player
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InventoryRemote = ReplicatedStorage:WaitForChild("InventoryRemote")
script.Parent.TextButton.MouseButton1Down:Connect(function()
print("Firing remote event")
local Item = {
Name = "TestItem",
Strength = 10,
Worth = 200
}
InventoryRemote:FireServer(Item)
end)
The Server - accesses the module script, invokes the function to the client and so on
local ServerScriptService = game:WaitForChild("ServerScriptService")
local req = require(ServerScriptService.PlayerData)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InventoryFunction = Instance.new("RemoteFunction")
InventoryFunction.Parent = ReplicatedStorage
InventoryFunction.Name = "InventoryFunction"
local InventoryRemote = Instance.new("RemoteEvent")
InventoryRemote.Name = "InventoryRemote"
InventoryRemote.Parent = ReplicatedStorage
local function PrintItems(player, item)
if req.Items[item.Name] then
local Item = req.Items[item.Name]
print("ITEM EXISTS!")
InventoryFunction:InvokeClient(player, Item)
else
print("Item does NOT exist")
end
print("Fired server event thanks to", player.Name)
end
InventoryRemote.OnServerEvent:Connect(PrintItems)
The local script, this will update the inventory whenever it’s invoked from the server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateInventory = ReplicatedStorage:WaitForChild("InventoryFunction")
local Inventory = script.Parent:WaitForChild("Inventory")
local function InvokeInventory(player, testInventory)
print("INVOKED INVENTORY")
print(testInventory)
end
UpdateInventory.OnClientInvoke = InvokeInventory
The player argument for the remote function at the moment will return nil, if you know of this please don’t deviate by trying to help me with it. I’m not focused on that right now.