How to constantly check for a seat within a certain radius?

Hey everyone! I am working on a taxi system but in order to make the character move to a seat, I will need to constantly check for seats within a certain area. I am having trouble with this as magnitude needs a specified part to work. I also tried making a touched event but that would not be ideal as the passenger will be moving around the map.

How would I go about doing this in an efficient manner? Thanks.

1 Like

Why not parent the seats you want to check within the same model/folder? That way you can cycle through each seat using the following.

for _, v in pairs(workspace.Model:GetChildren()) do
	if v:IsA("Seat") then
		--code here
	end
end

Could possibly use CollectionService to tag a new Seat each time a Taxi is added & then loop through the Table using magnitudes to see whether the NPC is close enough.

You can use the newer spatial query API, and you can make it more efficient due to overlap params so you can whitelist your passengers using OverlapParams instead of detecting uneeded parts: