So I am working on a backpack/inventory system for my game but this script appears to not be working. It works on studio, but doesn't in the actual game. Here is the script and if you need more information, let me know! Thank you!
local Items = {} local frames = {} local Equiped = nil local Player = game.Players.LocalPlayer local character = Player.Character game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) function Scan(location) for i,v in pairs(location:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then table.insert(Items,v) end end end Scan(character) Scan(Player.Backpack) function Update() print(Equiped) for i,v in pairs(frames) do v:Destroy() end for i,v in pairs(Items) do local sam = script.Sample:Clone() sam.Name = v.Name sam.Parent = script.Parent.Holder sam.ImageLabel.Image = v.TextureId sam.Text = v.Name table.insert(frames,sam) if Equiped ~= nil and Equiped == v then sam.BorderSizePixel = 2 end sam.MouseButton1Click:connect(function() if Equiped == nil or Equiped ~= v then Equiped = v character.Humanoid:UnequipTools() character.Humanoid:EquipTool(v) else Equiped = nil character.Humanoid:UnequipTools() end end) end end function backpackchanged() Items = {} Scan(character) Scan(Player.Backpack) Update() end backpackchanged() Player.Backpack.ChildAdded:connect(backpackchanged) Player.Backpack.ChildRemoved:connect(backpackchanged) character.ChildAdded:connect(backpackchanged) character.ChildRemoved:connect(backpackchanged)