In my game, I am trying to implement a system where you sacrifice items in your inventory to gain a permanent boost. To do this, the player selects the items in their inventory they want to sacrifice. This leaves them with an index of items that they are sacrificing akin to this:
{
[1] = 1, -- index means nothing, value is the id of the item being sacrificed
[2] = 2,
[3] = 3, -- so on and so forth
}
This array, created by a local GUI script, is supposed to be sent using FireServer to a server-sided module script that removes the items within the player’s inventory and updates a boost accordingly. (indexToBurn is the sent index)
torchEvent.OnServerEvent:Connect(function(player, indexToBurn)
local totalWorksBurning = 0
print(player.Name, indexToBurn)
for index, value in ipairs(indexToBurn) do
However, the function does not receive the index and instead, indexToBurn is an “Instance” that the code prints as nil. From what I read this is because the server script does not have access to the index within the local GUI script, so the server script cannot read it.
ServerScriptService.PlayerWorkIndex:55: invalid argument #1 to ‘ipairs’ (table expected, got Instance)
(Switching ipairs to pairs has the same result.)
My issue is that I still need to have the index accessible to the server script. Is there any alternative way for me to accomplish this, or am I possibly misinterpreting how FireServer works?