So Im making a custom item display thingy and so far it works with one item but when you have two it starts to display the same item twice.
So I have in my code a place that prints all the items and it does print the 2 different items (RangedWeapon and Other Thing) but when it actually displays it it displays the same item twice! Why?
local nums = {
[1] = 'One',
[2] = 'Two',
[3] = 'Three',
[4] = 'Four',
[5] = 'Five',
[6] = 'Six',
[7] = 'Seven',
[8] = 'Eight',
[9] = 'Nine',
[0] = 'Zero'
}
local equippedItem = nil
local function refresh()
for _, item in pairs(playerFrame:FindFirstChild('Items'):GetChildren()) do
if item:IsA('GuiObject') then
item:Destroy()
end
end
hum:UnequipTools()
warn(player:FindFirstChild('Backpack'):GetChildren())
for num,item in pairs(player:FindFirstChild('Backpack'):GetChildren()) do
warn(num,item)
if item:IsA('Tool') then -- make sure its a tool
local tag = script:FindFirstChild('Item'):Clone() -- create item tag for it
tag:FindFirstChild('ItemName').Text = string.upper(item.Name) -- set name
tag:FindFirstChild('Num').Text = '['..num..']' -- set num
tag.Parent = playerFrame:FindFirstChild('Items') -- parent it
if item == equippedItem then -- if it is equipped
tag:FindFirstChild('UIStroke').Color = Color3.new(1, 0.666667, 0)
tag:FindFirstChild('UIStroke').Thickness = 4
end
local connect = UIS.InputBegan:Connect(function(input,g)
if not g then
if input.KeyCode == Enum.KeyCode[nums[num]] then
hum:UnequipTools()
if item ~= equippedItem then -- equip it
hum:EquipTool(item)
equippedItem = item
tag:FindFirstChild('UIStroke').Color = Color3.new(1, 0.666667, 0)
tag:FindFirstChild('UIStroke').Thickness = 4
else
equippedItem = nil
end
end
end
end)
tag.Destroying:Wait()
connect:Disconnect()
end
end
end
task.spawn(refresh)
local ItemsCHeck = player:FindFirstChild('Backpack').ChildAdded:Connect(function()
task.spawn(refresh)
end)