Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make quantity show if the item is the same?

Asked by 7 years ago

im trying to make an inventory that has items like this

this

right now it's making Text Labels for each item. i have 3 weapons so far. 2 are the same name

    local TB = Instance.new("TextButton")
                TB.Parent = new
                TB.Position = UDim2.new(0,555,0,0)
                TB.BackgroundTransparency = 1
                TB.Size = UDim2.new(0,25,0,10)
                TB.BackgroundColor3 = Color3.fromRGB(255,255,255)
                TB.BorderColor3 = Color3.fromRGB(0,144,211)
                TB.BorderSizePixel = 1
                TB.ZIndex = 2
                TB.Text = "[Send]"
                TB.Name = Weapons[i].Name
                TB.MouseButton1Down:connect(function(clicked)
                    local number = 0

                    if Weapons[i].Name == Weapons[i].Name   then 
                        print(#Weapons)
                        number = number + [item number here]


                    end

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Alright, so i guess your question is that you check the quantity of the items in the backpack (Or, in your case, TextLabels) With this super easy script you can check the quantity of ANYTHING. Here's the code:

local itemquantity = 0
local itemparent = :GetChildren() -- Put the parent of the textlabels before the GetChildren
local itemname = "Example" -- This is just an example, put your name here
for x = 1, #itemparent do
    if itemparent[x].Name == itemname then -- This line and the line above checks every child in the parent
        itemquantity = itemquantity + 1 -- Adds 1 to itemquantity if it finds the item with the itemname
    end
end

wait()

if itemquantity > 1 then
    --Your code here
end

Hope this helped you

EDIT: The multiple version is SUPER easy, just copy paste the same code and just change the names, like this:

local itemquantity2= 0
local itemparent2 = :GetChildren() -- Put the parent of the textlabels before the GetChildren
local itemname2 = "Example" -- This is just an example, put your name here
for x = 1, #itemparent2 do
    if itemparent2[x].Name == itemname2 then -- This line and the line above checks every child in the parent
        itemquantity2 = itemquantity2 + 1 -- Adds 1 to itemquantity if it finds the item with the itemname
    end
end

wait()

if itemquantity2 > 1 then
    --Your code hre
end

There you go.

0
nevermind figured it out. thanks AwesomeSauce666556 0 — 7y
0
Ill edit the comment so that you can do it with multiple items, OK? BakonBot 26 — 7y
0
Oh. It's ok. Thank you for marking my answer. This is my first reputation point :) BakonBot 26 — 7y
0
one other thing. how can i remove the duplicate in the inventory? the same item has 2 labels right now AwesomeSauce666556 0 — 7y
Ad

Answer this question