Still have questions? Join our Discord server and get real time help.
0

# How can i edit this inventory system script so it puts all of the purchased tools??

Asked by 7 days ago

Im trying to make a inventory system for a simulator im working on but this script only puts the tool that a player has equipped in the inventory. How can i make it so it puts all of the tools a player has purchased. I also want it so it puts the backpack/storages (accessory) in the inventory. Can anyone help me? Heres the script

local player = game.Players.LocalPlayer
local character = player.Character
local items = {}
local buttons = {}
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) -- Makes the original backpack gui invisible

function search(location)
for i,v in pairs(location:GetChildren()) do -- Find all item in a specific location
if v:isA("Tool") then -- If the item found is a "Tool"
table.insert(items,v)
end
end
end

function refresh()
for i,v in pairs(buttons) do -- Finds all items in the table
v:Destroy() -- Destroy 'em all
end
for i,v in pairs(items) do -- Finds all items in the table
local button = script.Sample:Clone() -- clones the sample button inside the localscript
button.Name = v.Name -- sets the cloned button's name to the name of the item
button.LayoutOrder = i
button.Parent = script.Parent.Handler -- Sets the parent of the cloned button to the handler
button.Image = v.TextureId -- Sets the image of the button to the texture id of the tool
table.insert(buttons,button) -- Inserts the button to our table "buttons"
button.MouseButton1Click:connect(function()
if script.Parent.Handler.Selected.Value == nil or script.Parent.Handler.Selected.Value ~= v then -- Checks if the selected value is nothing or if the selected value is not the button
script.Parent.Frame.ItemName.Text = v.Name -- Sets the TextLabel's Text to the name of the tool/button
script.Parent.Frame.ImageLabel.Image = v.TextureId -- Sets the image label's image to the texture id of the tool
script.Parent.Handler.Selected.Value = v
if script.Parent.Handler.Selected.Value ~= script.Parent.Handler.Equipped.Value then --if the selected value is not the same as the equipped value then
script.Parent.Handler.Location.Value = v.Parent -- Sets the value of our location to the parent of the tool whether it is in the backpack or in the character
script.Parent.Frame.Equip.Text = "Equip" -- Self explanatory
elseif script.Parent.Handler.Selected.Value == script.Parent.Handler.Equipped.Value then -- If the selected value is the same as the equipped value then...
script.Parent.Handler.Location.Value = v.Parent
script.Parent.Frame.Equip.Text = "Unequip"
end
end
end)
end
end

function backpackRefresh()
items = {}
search(character)
search(player.Backpack)
refresh()
end

backpackRefresh()