Guys i have a quick question

Guys is it good if i put part.Touched() in a while loop, here is an example:

local Part = workspace.Part
while wait() do
    Part.Frame.Text.Text = Part.RandomValue.Value
    Part.Touched:Connect(function(PartTouched)
        print(PartTouched)
        Part.RandomValue.Value = "a random string here"
    end)
end

the only reason i want to ask this question is that i want to keep the text from updating but i feel like the touched function will be inefficient or not secure or something

3 Likes

the while loop is unnedded if you want it to only update when the part is touched. it will always happen if you call .Touched:Connect(function) regardless if its inside a loop or no

1 Like

i know is unneeded for that example but for me i have a for loop that runs through all of my parts.
if i dont put it in a for loop then it wont get the part, but if i dont put the for loop in the while loop the text wont update

i might make 2 for loops in my case so the touched event wont get effected by the while loop

1 Like

inside a for loop the text will still update when each part is touched no need for the while loop

no i want the text to update when the part is NOT touched (and touched but i can put it in the touched event so no problem here)

I believe that could result in stuff like memory leaks since you create a whole new listener each time it loops.

you could make a sepereate while loop and a for loop containing the touch event outside the while loop to avoid connections every wait()

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.