I have a folder with multiple text buttons, how would I cause an event to happen when one of them is clicked?

So, I have a folder with multiple text buttons all containing player information. When one of these textButtons are clicked, I want that information to be added onto a TextButton depending on which one has been clicked. This will then send some information through to the server which can include the player’s name. How would I find out which TextButton has been clicked?

1 Like

If it is just an organization issue, I recommend naming all of the TextButtons to your liking so they are all unique. That way the scripting will be an easier thing to do when defining which button was clicked.

1 Like

Yes, the TextButtons are already named correlating to the username of the player. All of which are visible, I just want to figure out which one was clicked and when.

1 Like

when sending information to the server, just pass the button’s name as another parameter , like :

when sending data

local button = button
button.MouseButton1Click:Connect(function()
  event:FireServer(tostring(button.Name))

and receive it though the server

Event.OnServerEvent:Connect(function(player,text))
  print("the button that was clicked was called"..text)
1 Like

I know how to send things through the server, but that isn’t what I meant. I wanted to find out which exact button was clicked as there are multiple within the server (Could be 20+ buttons) and I thought there was an alternative to putting this script into every single button.

1 Like

You don’t have to put this in every single button, just use a generic loop with the
ipairs generator, putting the script in every single button would be very redundant.

How:

local folder = folder -- I don't know where your folder is
 for _, button in ipairs(folder:GetChildren()) do
     button.MouseButton1Click:Connect(function()
     local name = button.Name
  event:FireServer(tostring(button.Name))
  end
end)
2 Likes

Wait, I thought this would work but doesn’t seem to be actually working. Here is my code:

local ScrollingFrame = Players.LocalPlayer:WaitForChild("PlayerGui").Cashier.partyFrame.ScrollingFrame 
local PlayerNames = ScrollingFrame.PlayerNames -- this accesses the folder

for i,v in ipairs(PlayerNames:GetChildren()) do
	v.MouseButton1Click:Connect(function()
        print(v.Name)
	end)
end

This should work, have you tried adding a print statement before the iteration and seen the output? if there is an error then the iteration would have never occured.

Edit : you’re sure it’s not a script running on the server? that it is a local script and is a descendant of the player?

Edit 2 :where is the script located? have you tried printing tostring(button.Name) instead
@RyanTheLion911 can you give my the exact details of where you’re using this local script in and the new code

This has all been done in a local script, but I don’t see why that would cause an issue as the folder is found on the client side.

Yes, even changing it to .tostring does nothing.