I’ve created a script that unloads certain islands if you aren’t close enough to them.
However, this has caused lag due to me performing a for loop every second, checking for the closest part to the player on every island.
Is there anyway I could optimize this?
Are there any indicators that tell you a player is far from an island? For example, a teleport script that teleports one island to the other?
If so, instead of looping you can just logically check where the player is by keeping tabs on what island they just recently teleported to.
Using this information you can unload islands without a huge loop.
There is no island teleport, just an indicator that a player is currently on a island once close enough, however, that’s when the player is under a brick, and it doesn’t calculate distance.
In the loop, what’re you doing to check if the player is in distance? How many objects are you checking?
For every area, I’m searching through every desecdant and trying to find a BasePart.
for i, v in pairs(area:GetDescendants()) do
if v:IsA("BasePart") and isInRegion3(region, v.Position) then
return true
end
end
How about have one invisible block that covers the island and checks if it’s in region.
Checking tons of parts is a terrible idea.
Alright, I’ll try that idea out.