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

Detect clicks for multiple TextButtons?

Asked by 5 years ago

I have a loop that creates multiple TextButtons depending on the players inventory, each TextButton features the same name but with a unique NumberValue instance inside of it to differentiate between.

Currently I'm using this method to detect clicks, but it seems to not be working with the auto generated TextButtons. Do you have any advice how to handle this problem? as I want each button to be clickable.

yScreenMenu.Inventory.ScrollingFrame.TheInventoryItem.MouseButton1Click:connect(function()
    --Not detecting
end)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

you can use a for loop which literates through a table, so you can use :GetChildren() as it returns a array or well a table and use the variable.

local buttons = script.Parent.Parent:GetChildren() -- define where all the textbuttons are

for _,v in pairs(buttons) do -- "v" can be named anything
    v.MouseButton1Click:Connect(function()
        --do stuff
    end)
end
0
Genius, very smart. Thank be to you sir. nestriff 27 — 5y
Ad

Answer this question