How should I do this? Looping through parts n stuff

So I have some parts that I dont want certain teams to be able to enter, now my question is how I should go about checking when the player enters, Should I use runservice.heartbeat in order to check if someone is in it or a while loop or some other way? I’m trying to make this as optimized as possible

the most optimized approach would be just looping through the parts once and connecting them to a .Touched event

.touched is incredibly bad due to it not running if you very quickly move through it, therefore this wont exactly work in my situation

try to use Mangitude
Ex: (Part.Position - Character.HumanoidRootPart.Position).Magnitude <= (Size of object)

I already have a method to see if a player is in the area, what I need is what way is best to run this function like a while loop, runservice.heartbeat etc

The best way probaly is to use while loop

Ex: While true do repeat until end

Ok Thanks! I guess yeah if I add a wait in there itll be much more optimized ig

idk how i opened my browser to this thread but u should check this module out:

1 Like

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