Ok so I have a huge amount of textbuttons named the same I click a trash can icon then I want to delete the one I click
Create a boolvalue, “isDeleting” or the like
Upon detecting a click on a textbutton and isDeleting.Value == true then destroy the textbutton
I mean how do I detect if some of those hundreds of buttons is clicked
button.Activated:Connect(function()
button:Destroy()
end)
If you want to delete a larger frame that contains the button, make sure the button is always inside that frame and do something like:
local frame = button.Parent
button.Activated:Connect(function()
frame:Destroy() --this will also delete the button, since it's inside the frame
end)
no because I have over 100 buttons I’m trying to figure out how to detect if any of them are clicked
Use a for loop to iterate through the children in the frame containing the textbuttons and you will only have to write the function once. Disconnect the function once the textbutton is deleted to prevent memory leaks
Otherwise just clone the script to every textbutton
this might help or give you an idea.
local TrashIcon = --defineTrashIcon button
local Buttons = --define Parent of buttons
local DeleteMode = false
TrashIcon.MouseButton1Down:Connect(function()
DeleteMode = not DeleteMode --toggle
end)
for _, Button in Buttons:GetChildren() do
Button.MouseButton1Down:Connect(function()
if DeleteMode then Button:Destroy() end
end)
end
thanks I’ll try it and if it works I’ll mark your post as the Solution!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.