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

[Solved]Why is this Touched event failing to work more than once or twice?

Asked by 6 years ago
Edited 6 years ago

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!

0
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! TheGreatSailor 20 — 6y
0
Sorry. I dont understand how that would work User#21908 42 — 6y

Answer this question