So I have an inventory system and I wanna make it so you can sell towers, right now, it removes it from the data but it doesn’t seem to update on the client though when you wanna equip or unequip something it works fine. I have to close and reopen the inventory for it to work? Heres the code on the client:
--for equipping something
local function interactItem(itemName)
local data = interactItemFunc:InvokeServer(itemName)
if data then
playerData = data
updateItems()
end
end
--for selling something
function sellUnit(itemName)
print(itemName)
if itemName and sellingUnits == true then
local canSell = sellFunc:InvokeServer(itemName)
updateItems()
if canSell then
updateItems()
end
end
end
And then of course, here it is on the server:
--equipping something
replicatedStorage.InteractItem.OnServerInvoke = function(player, itemName)
replicatedStorage.GuiInteract:FireClient(player)
local shopItem = getTowerByKey(itemName)
local playerData = data[player.UserId]
if shopItem and playerData then--if it exists and player has some data
local status = getItemStatus(player,itemName)
if status == "Owned" then
--equip the tower
if not table.find(playerData.SelectedTowers,shopItem.Name) then
table.insert(playerData.SelectedTowers, shopItem.Name)
end
if #playerData.SelectedTowers > playerData.MaxTowers then
table.remove(playerData.SelectedTowers, 1)
end
elseif status == "Equipped" then
--unselect(if more that 1 selected)
local towerToRemove = table.find(playerData.SelectedTowers, itemName)
table.remove(playerData.SelectedTowers, towerToRemove)
end
print(data[player.UserId].SelectedTowers)
return playerData
else
warn("Tower/player data does not exist")
end
return false--if something went wrong
end
--selling something
sellUnitFunc.OnServerInvoke = function(playerWhoSell,itemName)
print(playerWhoSell,itemName)
local shopItem = getTowerByKey(itemName)
local playerData = data[playerWhoSell.UserId]
if shopItem and playerData then--if it exists and player has some data
local status = getItemStatus(playerWhoSell,itemName)
if status == "Owned" then
--equip the tower
local towerToRemove = table.find(playerData.OwnedTowers, itemName)
table.remove(playerData.OwnedTowers, towerToRemove)
elseif status == "Equipped" then
--unselect(if more that 1 selected)
local towerToRemove = table.find(playerData.SelectedTowers, itemName)
table.remove(playerData.SelectedTowers, towerToRemove)
end
print(data[playerWhoSell.UserId].SelectedTowers)
print(data[playerWhoSell.UserId].OwnedTowers)
replicatedStorage.GuiInteract:FireClient(playerWhoSell)
updateEvent:FireClient(playerWhoSell, data[playerWhoSell.UserId].Gems)
return playerData
else
warn("Tower/player data does not exist")
end
return false--if something went wrong
end
(the GuiInteract and updateEvent are different don’t worry about those) Any help is appreciated, thanks!