I have a loop which goes through a bunch of buttons in a model and detects when they are touched, but as the title states it is failing to work properly. Here is the code:
function itemPurchasingManager(tycoonBaseplate, serverBaseplate, tycoon)
for i,v in pairs(tycoonBaseplate.Buttons:GetChildren()) do
v.Head.Touched:Connect(function(hit) -- Head is inside of a model which contains a humanoid and of course Head which is a part.
print("Button was touched") -- this is only printing once or twice and sometimes not at all
Can someone help me? There are no if statements in front of the print so that is not the problem. I know that the script is calling the function properly. So that is not the problem either. I wonder if the touched event wont work after the for loop is done?!? Please Help!

2 comments
I only just roughly looked at your code, to me it seems that after the for loop is done it won't run the touched event. You could flip it so you have a Head.Touched{for i,v in pairs.... if v == hit print(button was touched)}. Again could be totally wrong I just looked at it briefly good luck hope you can figure this out!
Sorry. I dont understand how that would work