local function GetTouchingParts(part)
local Connection = part.Touched:Connect(function() end)
local Results = part:GetTouchingParts()
while wait() do
for _, touching in pairs(GetTouchingParts(Character.PrimaryPart)) do
if touching.Parent == Region3s then
if touching.Name == 'CampSite' then
It’s inside a spawn function as it’s in a module, and a while loop wont return the module. And a while loop because I need it constantly checking if player is touching said part.
Not surprised this is causing lag, considering you’re having your code check for physically intersected parts in a minimal-interval loop and subsequently connecting several empty Touched listeners with no debounces.
A less expensive method would be to check the position of the character’s root part relative to the campsite or some kind of proxy part that determines the area a player needs to be in to be considered in the camping zone. This can be done in two ways:
Create a Region3 around the site and check constantly if the root part is inside this Region3 (super inexpensive check of whether one position is inside a region or not)
Create an invisible part below the site (under the map) and downcast downwards, using a whitelist towards that part and check if an intersection with that part can be found