Hi! So for the inventory system I made there are equip buttons under each item. It looks like this:
When you equip an item, the text changes to unequip.
The problem is, if you have two items equipped, only one text button will say unequip instead of both of them. I don’t know what to change in my code to fix this.
Here is my code:
function updateInventory()
for i, child in pairs(invFrame.ShopGUI.Tools:GetChildren()) do
if child:IsA("ImageLabel") then child:Destroy() end
end
local ownedTrails = ownedTrailsFolder:GetChildren()
print(ownedTrails)
table.sort(ownedTrails, function(a, b)
return trailsFolder[a.Name].Price.Value < trailsFolder[b.Name].Price.Value or trailsFolder[a.Name].Price.Value == trailsFolder[b.Name].Price.Value and a.Name < b.Name
end)
for i, tool in pairs(ownedTrails) do
local item = script.InvItem:Clone()
item.Image = tool:WaitForChild("Folder").ImageLabel.Image
item.SelectButton.Text = "Equip"
item.Title.Text = tool.Name
item.Visible = true
item.Parent = invFrame.ShopGUI.Tools
item.SelectButton.MouseButton1Click:Connect(function()
local price = tool.Price.Value
local coins = player.leaderstats.Coins.Value
if item == SelectedTrail then
item.SelectButton.Text = "Equip"
SelectedTrail = nil
else
if player.OwnedTools:FindFirstChild(tool.Name) or (price <= coins) then
item.SelectButton.Text = "Unequip"
else
item.SelectButton.Text = "Unequip"
end
if SelectedTrail then
SelectedTrail.SelectButton.Text = "Equip"
end
SelectedTrail = item
end
TrailSelectedRE:FireServer(tool)
end)
end
end
The button text changes through this code here:
item.SelectButton.MouseButton1Click:Connect(function()
local price = tool.Price.Value
local coins = player.leaderstats.Coins.Value
if item == SelectedTrail then
item.SelectButton.Text = "Equip"
SelectedTrail = nil
else
if player.OwnedTools:FindFirstChild(tool.Name) or (price <= coins) then
item.SelectButton.Text = "Unequip"
else
item.SelectButton.Text = "Unequip"
end
if SelectedTrail then
SelectedTrail.SelectButton.Text = "Equip"
end
SelectedTrail = item
end
TrailSelectedRE:FireServer(tool)
end)
end
How do I make it so if both items are equipped in the players backpack, both text buttons will say “Unequip”

