I want this script to unload the chunks another script has made when a player leaves a specific area. But it just does the opposite it just removes the chunks the player is in instead of removing the chunks around the player
I have tried quite many things but none works. This is the script (btw this is my first devforum post)
game.Players.PlayerAdded:Connect(function(plr) LoadedChar = false plr.CharacterAdded:Connect(function(char) LoadedChar = true char.Humanoid.WalkSpeed = 100 end) repeat wait(2) until LoadedChar == true local Char = plr.Character local Root = Char:WaitForChild("HumanoidRootPart") local Pos = Root.Position local Render = game.ReplicatedStorage.RenderDistance.Value*4*8 local R = Region3.new(Vector3.new(Pos.X-Render,0,Pos.Z-Render), Vector3.new(Pos.X+Render,100,Pos.Z+Render)) repeat local t = 0 local NotInside = {} local PlayerDescendants = 0 local Players = game.Players:GetPlayers() for i = 1,#Players do for i = 1,#Players[i].Character:GetChildren() do PlayerDescendants = PlayerDescendants + 1 end wait() end print("Maximum = "..Render+#Players+PlayerDescendants) local Inside = workspace:FindPartsInRegion3(R, Render+#Players+PlayerDescendants) local Chunks = workspace.Ignore.ChunkParts:GetChildren() for c = 1,#Chunks do for i = 1,#Inside do if Inside[i] == Chunks[c] then t = t + 1 NotInside[t] = Chunks[c] print("NotInside") end end end for i = 1,t do local Chunk = NotInside[i] workspace.Terrain:FillBlock(Chunk.CFrame, Chunk.Size, "Air") print("Removed") end wait(1) until plr == nil end)