Hello so I have this inventory system that I made sorry if it sucks lol, but there’s a bug I encountered and can’t seem to find a workaround
So first of all whenever the player opens the inventory is when I request to get the data and obviously I think this is bad because every time the player opens the inventory I invoke server and so it can be spammed oof
local toggleInventory = screenGui.toggleInventory
toggleInventory.MouseButton1Click:Connect(function()
data = getData:InvokeServer() --server returns all the players data
profileFrame.Visible = not profileFrame.Visible
end)
This part basically waits until data ~= nil so the data is there and then it just makes a button for each item inside the data inventory table however an issue I had was If I needed to add new items so I simply just made an addItem event that I use when i need to make a new button (for my shop for example after a play buys an item) however I found out if the player buys an item from the shop and then opens the inventory well the inventory is gonna make duplicates of the items because it’s still on the repeat
repeat wait() until data ~= nil
--Inventory (creates a button for each item inside the inventory table)
for _,item in pairs(data.inventory) do
createButton(item)
end
--Equipped Items
for slot,item in pairs(data.equipped) do --this is the equipped data so the players currently equipped items if any
--print(item)
--if item ~= "" then --there is an item in the slot (I only store the name of the item)
--print(item,slot)
--This part will update the equipment slots to show if stuff is equipped (because we save the staff in the data so ye
for _,slotUI in pairs(equipmentSlots:GetChildren()) do --this is the equipmentSlot buttons so the ui
if string.lower(slotUI.Name) == slot and item ~= "" then --there IS something equipped in this slot so change the SlotUI text to it
slotUI.Text = item
end
slotUI.MouseEnter:Connect(function()
if slotUI.Name ~= slotUI.Text then
if deb == false then
deb = true
displayStats(slotUI.Text)
deb = false
end
end
end)
slotUI.MouseLeave:Connect(function()
itemInfoFrame.Visible = false
end)
--Unequip
slotUI.MouseButton1Click:Connect(function()
if deb == false then
deb = true
local scuessfullyUnequip = unequip:InvokeServer(slotUI.Text, slotUI.Name) --do some checks on the server to make sure it's all legit
if scuessfullyUnequip then
createButton(slotUI.Text)
slotUI.Text = slotUI.Name
else
warn("Couldn't unequip item")
end
deb = false
end
end)
end
--end
end
addItem.OnClientEvent:Connect(function(item)
createButton(item)
end)
So if anyone is able to help fix this issue that would be great thanks ![]()