Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Detect clicks for multiple TextButtons?

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

✓ Accepted answer

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

1 comment

0

Genius, very smart. Thank be to you sir.

This discussion is preserved as it was. New answers, comments, and votes are closed.