Hi. I made an inventory gui and asked my friend to find bugs. He discovered this problem when he spam opened the inventory
the inventory is displaying multiple guis of the same item when in reality the player only has one of each.
Heres my code:
--stock inventory
local playerinv = game.ReplicatedStorage.Remotes.GetSpinInv:InvokeServer()
for i,v in pairs(itemholder:GetChildren()) do
if v:IsA("ImageLabel") or v:IsA("TextButton") then
v:Destroy()
end
end
for i,v in pairs(playerinv) do
local iteminfo = require(game.ReplicatedStorage.Spinners[v])
local button = Instance.new("TextButton")
button.BackgroundTransparency = 1
button.TextTransparency = 1
button.Text = "Banana"
button.ZIndex = 3
button.LayoutOrder = iteminfo.Order
local roundframe = game.ReplicatedStorage.Extras.RoundFrame:Clone()
roundframe.Size = UDim2.new(1,0,1,0)
if v == player.Stats.EquippedSpinner.Value then
roundframe.ImageColor3 = ownedcolor
else
roundframe.ImageColor3 = normalcolor
end
roundframe.Parent = button
local imagedis = Instance.new("ImageLabel", roundframe)
imagedis.BackgroundTransparency = 1
imagedis.Size = UDim2.new(1,0,1,0)
imagedis.Image = iteminfo.Texture
button.Parent = itemholder
end
-- setting up gridlayout
local totalpadding = gridlayout.CellPadding.X.Scale * (maxperline - 1)
local actualScale = (1 - totalpadding) / maxperline
local sizeX = itemholder.AbsoluteSize.X * actualScale
gridlayout.CellSize = UDim2.new(0, sizeX, 0, sizeX)
itemholder.CanvasSize = UDim2.new(0, 0, 0, gridlayout.AbsoluteContentSize.Y)
if you see any variables that werent indexed in the code, they were probably indexed at the beginning of the localscript
This function will fire everytime the player:
- earns EXP from weapons (which the player gets everytime they get a hit with the gun)
- changes their gun/spinner
- opens the inventory GUI
- changes the inventory mode (Weapons/Spinners)
Is there a way to make sure the gui doesnt display the same item twice?