So currently I have a custom backpack however I'm unsure how I could change the order of the layout of weapons. I'd like to have the ranged weapons (ie guns, bows) in slot 1 and melee weapons (ie swords, bats) in slot 2. For Example, If I had a sword named "AzureSword" and a gun named "Pistol" then the sword will be in slot 1 and the pistol will be in slot 2, based off of alphabetical order. I'm not sure how I could get around this without renaming the weapons. Does anyone have any ideas?
Not sure if this is useful but, custom backpack script:
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") then table.insert(Items,v) end end end 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)
Create a two tables, "Primary" and "Secondary"
local Primary = {"AzureSword"} -- list of primary weapon names (string only) local Secondary = {"Pistol"} -- list of secondary weapon names
Use a loop to check if the weapon is a primary/secondary
local Primary = {"AzureSword"} local Secondary = {"Pistol"} function checkPrimary(tool, location) for i = 1, #Primary do if (tool.Name == Primary[i]) then tool.Parent = location else checkSecondary(tool. location) end end end function checkSecondary(tool, location) for i = 1, #Secondary do if (tool.Name== Secondary[i]) then tool.Parent = location end end end function giveTool() -- remove this just an example of how to use the function for _, v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do if v:IsA("Tool") then checkPrimary(v, game.Players.LocalPlayer.Backpack) end end end