Okay So I Am Trying To Make A Inventory System The Hot Bar Equip/ Unequip And Storing In Inventory Works But When I Pick Up A Item When My Inventory Is Filled The Item Glitches Like It Gets Parented To Another Are But When it Does All Of My Items In The HotBar Dissapears And When Its Parented To The Workspace All Items Are Doubled.. Why Doe?
Local Script
local Tools = {} game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) local Num = 0 local Inventory = {} local NumToWords = { [1] = "One", [2] = "Two", [3] = "Three", [4] = "Four", [5] = "Five", [6] = "Six", [7] = "Seven", [8] = "Eight", [9] = "Nine", [10] = "Zero", } -- Updates Hotbar local function updatehotbar() -- Deletes Old Stuff for i,v in pairs(script.Parent.Frame:GetChildren()) do if v:IsA("TextButton") then v:Destroy() end end -- Cap if #Tools > 10 then table.insert(Inventory,#Inventory+1,Tools[#Tools]) table.remove(Tools,#Tools) print("HotBar Filled ",Tools) if #Inventory <= 2 then local temp = script.Temp:Clone() temp.Parent = script.Parent.Inventory.StoreArea temp.Text = Inventory[#Inventory].Name temp.Num:Destroy() temp.Name = Inventory[#Inventory].Name else local object = Inventory[#Inventory] object.Parent = game.ReplicatedStorage table.remove(Inventory,#Inventory) print("Inventroy Filled ", Inventory) wait(5) object.Parent = game.Workspace end end -- Makes Stuff for i,v in pairs(Tools) do local temp = script.Temp:Clone() if #Tools < 11 then temp.Parent = script.Parent.Frame end if i == 10 then temp:WaitForChild('Num').Text = 0 else temp:WaitForChild('Num').Text = i end temp.Text = v.Name temp.Name = v.Name end end -- NewTool Added local Childd game.Players.LocalPlayer.Backpack.ChildAdded:Connect(function(Child) if Child ~= Childd and #Tools < 11 then table.insert(Tools,#Tools+1,Child) Num =Num + 1 end updatehotbar() end) -- Tool Removed game.Players.LocalPlayer.Backpack.ChildRemoved:Connect(function(Child) if Child.Parent ~= game.Players.LocalPlayer.Character then table.remove(Tools,Tools[Child]) Num =Num - 1 else Childd = Child end updatehotbar() end) -- When Tool Is Picked game.Players.LocalPlayer.Character.ChildAdded:Connect(function(Child) if Child ~= Childd then game.ReplicatedStorage.UnEquipTools:FireServer() end end) local equipped = false local db = false -- Unequip / Equip game:GetService("RunService").RenderStepped:Connect(function() for i,v in pairs(Tools) do game:GetService("UserInputService").InputBegan:Connect(function(In) if In.KeyCode == Enum.KeyCode[NumToWords[i]] and v.Parent == game.Players.LocalPlayer.Backpack or v.Parent == game.Players.LocalPlayer.Character then if not db then db = true if not equipped then equipped = true game.ReplicatedStorage.EquipTools:FireServer(v) else game.ReplicatedStorage.UnEquipTools:FireServer() equipped = false end wait(0.2) db = false end end end) end end)
Server Script
game.ReplicatedStorage.UnEquipTools.OnServerEvent:Connect(function(Plr) local Human = Plr.Character.Humanoid Human:UnequipTools() end) game.ReplicatedStorage.EquipTools.OnServerEvent:Connect(function(Plr,Tool) local Human = Plr.Character.Humanoid Human:EquipTool(Tool) end)