Custom Inventory Cloning same thing twice?
Asked by
3 years ago Edited 3 years ago
Basically, I'm making a Custom Inventory Gui. Theres a bug where it shows 2 of the same item, even though I don't want it to.
I've tried clearing the 2 tables in this script before the cloning process. I've tried adding wait() arguments (that just made things worse lol).
this is the script:
001 | local player = game.Players.LocalPlayer |
002 | local character = player.Character |
005 | local equipped = script.Parent.Handler.Equipped |
006 | local selected = script.Parent.Handler.Selected |
007 | local location = script.Parent.Handler.Location |
008 | game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false ) |
010 | player:WaitForChild( "Backpack" ) |
012 | script.Parent.Parent.Parent:WaitForChild( "PlayerMain" ) |
014 | function search(location) |
015 | for i,v in ipairs (location:GetChildren()) do |
016 | if v:IsA( "Tool" ) then |
017 | table.insert(items,v) |
023 | for i,v in ipairs (items) do |
024 | table.remove(items,v) |
027 | for i,v in ipairs (buttons) do |
033 | for i,v in ipairs (items) do |
034 | local button = script.Sample:Clone() |
036 | button.LayoutOrder = i |
037 | button.Parent = script.Parent.Handler |
038 | button.Image = v.TextureId |
040 | button.BackgroundColor 3 = Color 3. fromRGB( 50 , 50 , 50 ) |
041 | button.BorderColor 3 = Color 3. fromRGB( 25 , 25 , 25 ) |
042 | button.BorderMode = Enum.BorderMode.Outline |
043 | button.BorderSizePixel = 3 |
044 | table.insert(buttons,button) |
045 | button.MouseEnter:Connect( function () |
046 | if script.Parent.Handler.Selected.Value = = nil or script.Parent.Handler.Selected.Value ~ = v then |
047 | if button:GetAttribute( "ItemEquipped" ) = = false then |
048 | button.BorderColor 3 = Color 3. fromRGB( 255 , 0 , 0 ) |
050 | script.Parent.Frame.ItemStats.ItemName.Text = v.Name |
051 | script.Parent.Frame.ItemStats.ItemLevel.Text = "Lv. " ..v:GetAttribute( "Level" ) |
052 | script.Parent.Frame.ItemStats.ItemDesc.Text = "" ..v:GetAttribute( "Description" ) |
053 | script.Parent.Frame.ImageLabel.Image = v.TextureId |
055 | location.Value = v.Parent |
057 | button.MouseLeave:Connect( function () |
058 | if button:GetAttribute( "ItemEquipped" ) = = false then |
059 | button.BorderColor 3 = Color 3. fromRGB( 25 , 25 , 25 ) |
061 | script.Parent.Frame.ItemStats.ItemName.Text = "(Nothing)" |
062 | script.Parent.Frame.ItemStats.ItemLevel.Text = "Lv. NaN" |
063 | script.Parent.Frame.ItemStats.ItemDesc.Text = "No Description" |
068 | button.MouseButton 1 Click:Connect( function () |
069 | if equipped.Value = = nil or equipped.Value ~ = selected.Value then |
070 | character.Humanoid:UnequipTools() |
071 | if location.Value = = player.Backpack then |
072 | character.Humanoid:EquipTool(selected.Value) |
073 | equipped.Value = selected.Value |
074 | button:SetAttribute( "ItemEquipped" , true ) |
075 | button.BorderColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
078 | character.Humanoid:UnequipTools() |
080 | button.EquipCheck.Visible = false |
081 | button:SetAttribute( "ItemEquipped" , false ) |
082 | button.BorderColor 3 = Color 3. fromRGB( 25 , 25 , 25 ) |
089 | function backpackRefresh() |
092 | search(game.Players.LocalPlayer.Character) |
093 | search(game.Players.LocalPlayer.Backpack) |
098 | if script.Parent.Visible = = true then |
099 | script.Parent.Parent.Frame.Visible = true |
100 | script.Parent.Parent.Parent.PlayerMain.Dark.Main.Visible = false |
101 | script.Parent.Parent.Parent.PlayerMain.Dark.StatHUD.Visible = false |
102 | elseif script.Parent.Visible = = false then |
103 | script.Parent.Parent.Frame.Visible = false |
104 | script.Parent.Parent.Parent.PlayerMain.Dark.Main.Visible = true |
105 | script.Parent.Parent.Parent.PlayerMain.Dark.StatHUD.Visible = true |
112 | player.Backpack.ChildAdded:Connect(backpackRefresh) |
113 | player.Backpack.ChildRemoved:Connect(backpackRefresh) |
115 | character.ChildAdded:Connect(backpackRefresh) |
116 | character.ChildRemoved:Connect(backpackRefresh) |
120 | script.Parent:GetPropertyChangedSignal( "Visible" ):Connect(FrameVis) |
this is the few parts that this script interacts with:
a peek on the explorer
Picture of the bug (in case you don't understand what i mean)