Minecraft-like Roblox block game rblx.games/135624152691584
roblox roblox-game rojo
at main 79 lines 2.2 kB view raw
1return { 2 Name = "chunkcull", 3 Aliases = {"cullchunks", "resetchunks"}, 4 Description = "Unload all server chunk cache instantly, then preload only chunks near players (and force clients to unload/resync).", 5 Group = "Admin", 6 Args = { 7 { 8 Type = "integer", 9 Name = "radius", 10 Description = "Horizontal chunk radius around each player to preload", 11 Optional = true, 12 Default = 5, 13 }, 14 { 15 Type = "integer", 16 Name = "yRadius", 17 Description = "Vertical chunk radius around each player to preload", 18 Optional = true, 19 Default = 1, 20 }, 21 }, 22 Run = function(context, radius, yRadius) 23 local ReplicatedStorage = game:GetService("ReplicatedStorage") 24 local Players = game:GetService("Players") 25 26 local terrainGen = require( 27 game:GetService("ServerScriptService") 28 :WaitForChild("Actor") 29 :WaitForChild("ServerChunkManager") 30 :WaitForChild("TerrainGen") 31 ) 32 33 local tickRemote = ReplicatedStorage:WaitForChild("Tick") 34 35 local r = radius or 5 36 local ry = yRadius or 1 37 38 local unloaded = 0 39 pcall(function() 40 unloaded = terrainGen:UnloadAllChunks() 41 end) 42 43 -- Tell all clients to immediately drop their local chunk instances 44 pcall(function() 45 tickRemote:FireAllClients("U_ALL", 0, 0, 0, 0, 0, 0, 0) 46 end) 47 48 -- Preload server chunks around players (reduces initial lag spikes after cull) 49 local preloaded = 0 50 pcall(function() 51 preloaded = terrainGen:PreloadNearPlayers(r, ry) 52 end) 53 54 -- Force clients to resync around themselves 55 local resyncCount = 0 56 for _, player in ipairs(Players:GetPlayers()) do 57 local character = player.Character 58 local root = character and character:FindFirstChild("HumanoidRootPart") 59 if root then 60 local pos = root.Position 61 local cx = math.floor((pos.X + 16) / 32) 62 local cy = math.floor((pos.Y + 16) / 32) 63 local cz = math.floor((pos.Z + 16) / 32) 64 for y = -ry, ry do 65 for x = -r, r do 66 for z = -r, r do 67 tickRemote:FireClient(player, "C_R", cx + x, cy + y, cz + z, 0, 0, 0, 0) 68 resyncCount += 1 69 end 70 end 71 end 72 end 73 end 74 75 return ( 76 "chunkcull done | unloaded=%d | preloaded=%d | resyncPackets=%d | radius=%d yRadius=%d" 77 ):format(unloaded, preloaded, resyncCount, r, ry) 78 end, 79}