--[[ town - Plot Copier / Saver v5 (Madium executor) ================================================ Run in Madium while in "town" (place 4991214437). WHAT IT DOES - Lists every plot under Workspace["Private Building Areas"]. - [Save] serializes a whole plot into JSON: parts, meshes, decals/textures, SurfaceAppearance maps, lights, beams/attachments, the exact saved constraints ("wiring"), attributes, transparency, and all readable settable properties. Written to PlotCopier/base_.json, copied to the clipboard. Saved bases appear in a numbered box (Base 1, Base 2, ...); click one to build it. - Click a plot name to expand that row. The expanded panel has visible Save, Build and Stop buttons. - [Build] recreates that plot on YOUR own auto-detected plot using Building Tools' persistent server endpoint, so parts persist for everyone. Parts are created one at a time with a selectable conservative random delay: 1-2s, 0.5-1s, or 0.25-0.5s. The choice is saved, the progress bar shows an ETA, and STOP cancels between parts. - "Clear plot x2" uses Building Tools' server Remove action. - Old v1 saves are still readable. NOTES - No permission is needed on the source plot. - You must own/claim a plot in-game for Build to work. - A "wire" is a direct Texture child with Transparency +/-500 (the game's SharedWiring rule). The Texture ID is the look (it may be empty), StudsPerTileU is the 1-12 type/speed (2=send, 3=receive), and the parent part's Color decides matching. The wire part's direct parent must be a real Model, so wire host Models are rebuilt server-side with CreateGroup. Decals and SpecialMeshes are still copied exactly but are not treated as wires. Parts, colors, materials, transparency, sizes, lights, decals/textures and SurfaceAppearance maps use server actions; legacy constraint objects remain client-side. ]] local HttpService = game:GetService("HttpService") local Players = game:GetService("Players") local Workspace = game:GetService("Workspace") local LocalPlayer = Players.LocalPlayer while not LocalPlayer do task.wait() LocalPlayer = Players.LocalPlayer end local PlayerGui = LocalPlayer:WaitForChild("PlayerGui") local CONFIG = { GUI_NAME = "PlotCopierGui", SAVE_FOLDER = "PlotCopier", SAVE_VERSION = 2, SERVER_BUILD = true, PART_MIN_DELAY = 1.0, -- default server speed; can be changed in the GUI PART_MAX_DELAY = 2.0, MAX_WAIT = 90, -- Conservative mode: create parts one at a time through the normal -- Building Tools action. This is slower, but it avoids bursts of server -- invokes. No hooks, no anti-cheat bypass, no direct remote fallback. PARALLEL_CREATE = false, CREATE_WINDOW = 1, } local statusLabel = nil local progressFill = nil local progressLabel = nil local logLabel = nil local logLines = {} local busy = false local buildRunning = false local stopRequested = false local unpackFn = unpack or table.unpack local lastWireCount = 0 local pendingClear = 0 -- User-selectable server placement speed. Three presets are exposed in the GUI; -- the chosen range is also saved to PlotCopier/settings.json. local SPEED_PRESETS = { { lo = 1.00, hi = 2.00, label = "1-2s" }, { lo = 0.50, hi = 1.00, label = "0.5-1s" }, { lo = 0.25, hi = 0.50, label = "0.25-0.5s" }, } local speedMin = CONFIG.PART_MIN_DELAY local speedMax = CONFIG.PART_MAX_DELAY local speedButtons = {} -- The game's SharedWiring.component recognizes a wire when a BasePart has a -- direct Texture child with |Transparency| >= 499.9999. The Texture ID is the -- wire look (it may be empty), StudsPerTileU is the 1-12 type/speed number -- (2 = send, 3 = receive), and the PARENT PART's Color decides whether a 2/3 -- pair connects. The parent part must also be inside a real Model: the game's -- Beam Connector only scans wire parts whose direct parent is a Model, so the -- copier rebuilds wire-host Models server-side with CreateGroup. -- Nothing is translated or guessed: SyncTexture/SyncColor assign these values -- directly, so exact values survive. local function isTexturedWire(inst, props) if not inst or inst.ClassName ~= "Texture" or type(props) ~= "table" then return false end local tr = props.Transparency if type(tr) == "table" then tr = tr[2] end return type(tr) == "number" and math.abs(tr) >= 499.9999 end -- Same rule as isTexturedWire, but for a serialized record before the object -- exists. Used to pre-scan which saved Models must become real server groups. local function recordIsWireTexture(e) if type(e) ~= "table" or e.cn ~= "Texture" or type(e.pr) ~= "table" then return false end local tr = e.pr.Transparency if type(tr) == "table" then tr = tr[2] end return type(tr) == "number" and math.abs(tr) >= 499.9999 end local function wireTypeNumber(props) if type(props) ~= "table" then return nil end local u = props.StudsPerTileU if type(u) == "table" then u = u[2] end if type(u) ~= "number" then return nil end if u >= 1 and u <= 12 and u == math.floor(u) then return tostring(u) end return nil end local function setStatus(msg, isError) msg = tostring(msg) table.insert(logLines, msg) while #logLines > 5 do table.remove(logLines, 1) end if logLabel and logLabel.Parent then logLabel.Text = " " .. table.concat(logLines, "\n") end if statusLabel and statusLabel.Parent then statusLabel.Text = msg statusLabel.TextColor3 = isError and Color3.fromRGB(255, 120, 120) or Color3.fromRGB(160, 220, 255) end end local log = setStatus local function setProgress(part, total, label) if progressFill and progressFill.Parent then local pct = 0 if total and total > 0 then pct = math.clamp(part / total, 0, 1) end progressFill.Size = UDim2.new(pct, 0, 1, 0) end if progressLabel and progressLabel.Parent then progressLabel.Text = label or (tostring(part) .. "/" .. tostring(total)) end end local function showError(msg) setStatus("ERROR: " .. tostring(msg), true) end local function safeCall(fn, ...) local ok, err = pcall(fn, ...) if not ok then showError(err) end return ok end -- The selected preset paces every object placement, including the local -- fallback used if the server endpoint is unavailable. local function buildDelay() local lo, hi = speedMin, speedMax if hi < lo then lo, hi = hi, lo end if hi <= 0 then return 0 end -- max speed: no intentional pacing return lo + math.random() * (hi - lo) end local function speedName() for _, p in ipairs(SPEED_PRESETS) do if math.abs(speedMin - p.lo) < 0.001 and math.abs(speedMax - p.hi) < 0.001 then return p.label end end return string.format("%.2g-%.2gs", speedMin, speedMax) end local function progressText(done, total, paced) local text = done .. "/" .. total if paced then local secs = math.ceil(math.max(0, total - done) * (speedMin + speedMax) * 0.5) if secs > 0 then text = text .. " (~" .. secs .. "s)" end end return text end -- Stop button: cancels between parts; the current server call is allowed to -- finish so the build is never left half-written. local function requestStop() if not buildRunning then log("No build is running") return end if stopRequested then log("Stop already requested") return end stopRequested = true log("Stop requested - finishing current part") end -- Pausable wait used by the pacing delays so Stop reacts immediately. local function waitWithStop(seconds) local deadline = os.clock() + math.max(0, seconds) while os.clock() < deadline do if stopRequested then return false end task.wait(math.min(0.1, deadline - os.clock())) end return not stopRequested end local function fsWrite(path, data) if typeof(writefile) ~= "function" then return false, "writefile unavailable" end return pcall(writefile, path, data) end local function fsRead(path) if typeof(readfile) ~= "function" then return false, "readfile unavailable" end return pcall(readfile, path) end local function fsList(folder) if typeof(listfiles) ~= "function" then return false, {} end return pcall(listfiles, folder) end local function fsMakeFolder(folder) if typeof(makefolder) == "function" then pcall(makefolder, folder) end end -- --------------------------------------------------------------------------- -- Build speed settings (persisted between runs) -- --------------------------------------------------------------------------- local function refreshSpeedButtons() for _, item in ipairs(speedButtons) do local active = math.abs(speedMin - item.lo) < 0.001 and math.abs(speedMax - item.hi) < 0.001 item.button.BackgroundColor3 = active and Color3.fromRGB(60, 150, 90) or Color3.fromRGB(58, 62, 84) end end local function setBuildSpeed(lo, hi, quiet) lo, hi = tonumber(lo), tonumber(hi) if not lo or not hi then return end if hi < lo then lo, hi = hi, lo end speedMin, speedMax = math.clamp(lo, 0, 10), math.clamp(hi, 0, 10) fsMakeFolder(CONFIG.SAVE_FOLDER) local ok, encoded = pcall(function() return HttpService:JSONEncode({ speedMin = speedMin, speedMax = speedMax }) end) if ok then pcall(fsWrite, CONFIG.SAVE_FOLDER .. "/settings.json", encoded) end refreshSpeedButtons() if statusLabel and statusLabel.Parent and tostring(statusLabel.Text):find("Ready", 1, true) then statusLabel.Text = " Ready - your plot is highlighted green | speed: " .. speedName() end if not quiet then log("Build speed set to " .. speedName() .. " per part") end end local function loadBuildSpeed() fsMakeFolder(CONFIG.SAVE_FOLDER) local ok, content = fsRead(CONFIG.SAVE_FOLDER .. "/settings.json") if not ok then return end local okDec, data = pcall(HttpService.JSONDecode, HttpService, content) if not okDec or type(data) ~= "table" then return end local lo, hi = tonumber(data.speedMin), tonumber(data.speedMax) -- Ignore any old file saved by the previous unsafe fast presets. if lo and hi and lo >= 0.25 and hi >= lo and hi <= 10 then speedMin, speedMax = lo, hi end end loadBuildSpeed() -- --------------------------------------------------------------------------- -- Plot helpers -- --------------------------------------------------------------------------- local function getAreas() return Workspace:FindFirstChild("Private Building Areas") end local function getPivot(inst) local ok, cf = pcall(function() if inst:IsA("PVInstance") then return inst:GetPivot() end if inst:IsA("BasePart") then return inst.CFrame end return CFrame.new(inst.Position) end) return ok and cf or CFrame.new() end local function plotOwnerName(plot) local perms = plot:FindFirstChild("[Permissions]") if perms then local owner = perms:FindFirstChild("Owner") if owner then if typeof(owner.Value) == "Instance" then return owner.Value.Name end return tostring(owner.Value) end end return plot.Name:gsub("BuildArea$", "") end -- Plot counts are relatively expensive on servers with many builds. A short -- cache keeps GUI refreshes and plot detection from stuttering. local plotCache, plotCacheAt = nil, 0 local function listPlots() local now = os.time() if plotCache and now - plotCacheAt < 2 then return plotCache end local result = {} local areas = getAreas() if not areas then return result end for _, plot in ipairs(areas:GetChildren()) do local build = plot:FindFirstChild("Build") if build then local parts, objects = 0, 0 for _, d in ipairs(build:GetDescendants()) do objects += 1 if d:IsA("BasePart") then parts += 1 end end table.insert(result, { plot = plot, build = build, name = plotOwnerName(plot), parts = parts, objects = objects, }) end end table.sort(result, function(a, b) return a.name < b.name end) plotCache, plotCacheAt = result, now return result end local function isMyPlot(plot) if plot.Name == LocalPlayer.Name .. "BuildArea" then return true end local perms = plot:FindFirstChild("[Permissions]") if perms then local owner = perms:FindFirstChild("Owner") if owner then local v = owner.Value if typeof(v) == "Instance" and v == LocalPlayer then return true end if type(v) == "string" and (v == LocalPlayer.Name or v == tostring(LocalPlayer.UserId)) then return true end if type(v) == "number" and v == LocalPlayer.UserId then return true end end for _, entry in ipairs(perms:GetChildren()) do if entry.Name == LocalPlayer.Name or entry.Name == tostring(LocalPlayer.UserId) then return true end if entry:IsA("ValueBase") then local v = entry.Value if typeof(v) == "Instance" and v == LocalPlayer then return true end if type(v) == "string" and (v == LocalPlayer.Name or v == tostring(LocalPlayer.UserId)) then return true end if type(v) == "number" and v == LocalPlayer.UserId then return true end end end end return false end local function findMyPlot() for _, entry in ipairs(listPlots()) do if isMyPlot(entry.plot) then return entry.plot, entry.build end end for _, inst in ipairs(Workspace:GetChildren()) do if inst:FindFirstChild("Build") and isMyPlot(inst) then return inst, inst.Build end end local function fromValues(root) for _, obj in ipairs(root:GetDescendants()) do if obj:IsA("ObjectValue") and obj.Name:lower():find("plot") then local v = obj.Value if v and v:FindFirstChild("Build") then return v, v.Build end end end return nil, nil end local p, b = fromValues(LocalPlayer) if p then return p, b end if LocalPlayer.Character then p, b = fromValues(LocalPlayer.Character) if p then return p, b end end return nil, nil end local function waitForCooling() -- Server-created BuildCooling needs a moment to replicate before checking. task.wait(0.1) local deadline = os.time() + CONFIG.MAX_WAIT while LocalPlayer:FindFirstChild("BuildCooling") do if stopRequested then return false end if os.time() > deadline then log("Timed out waiting for build cooldown", true) return false end task.wait(0.25) end return true end -- --------------------------------------------------------------------------- -- Serialization: tagged values keep types (CFrame, Color3, Enums, refs, etc.) -- --------------------------------------------------------------------------- local function round(n, places) if type(n) ~= "number" then return n end if n ~= n or n == math.huge or n == -math.huge then return 0 end local m = 10 ^ (places or 4) return math.floor(n * m + 0.5) / m end local function encValue(v, refs) local tt = typeof and typeof(v) or "" if tt == "Instance" then local idx = refs[v] if idx then return { "r", idx } end return nil end if tt == "CFrame" then local c = { v:components() } for i = 1, 12 do c[i] = round(c[i], 4) end return { "c", unpackFn(c) } end if tt == "Vector3" then return { "v", round(v.X, 4), round(v.Y, 4), round(v.Z, 4) } end if tt == "Vector2" then return { "w", round(v.X, 4), round(v.Y, 4) } end if tt == "Color3" then return { "k", round(v.R, 4), round(v.G, 4), round(v.B, 4) } end if tt == "UDim2" then return { "u", round(v.X.Scale, 4), round(v.X.Offset, 3), round(v.Y.Scale, 4), round(v.Y.Offset, 3) } end if tt == "EnumItem" then local ok, name = pcall(function() return v.Name end) local ok2, enumType = pcall(function() return tostring(v.EnumType) end) if ok and ok2 then return { "e", enumType, name } end return nil end if tt == "ColorSequence" then local out = { "cs" } for _, kp in ipairs(v.Keypoints) do table.insert(out, { round(kp.Time, 4), encValue(kp.Value, refs) }) end return out end if tt == "NumberSequence" then local out = { "ns" } for _, kp in ipairs(v.Keypoints) do table.insert(out, { round(kp.Time, 4), round(kp.Value, 4), round(kp.Envelope, 4) }) end return out end if type(v) == "number" then return round(v, 4) end if type(v) == "string" or type(v) == "boolean" then return v end if type(v) == "table" then local out = { "t" } for k, val in pairs(v) do local ek = encValue(k, refs) local ev = encValue(val, refs) if ek ~= nil and ev ~= nil then table.insert(out, { ek, ev }) end end if #out > 1 then return out end return nil end return nil end local function decValue(v, created) if type(v) ~= "table" then return true, v end local t = v[1] if t == "r" then local inst = created[v[2]] if inst then return true, inst end return false, nil end if t == "c" then return true, CFrame.new(v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13]) end if t == "v" then return true, Vector3.new(v[2], v[3], v[4]) end if t == "w" then return true, Vector2.new(v[2], v[3]) end if t == "k" then return true, Color3.new(v[2], v[3], v[4]) end if t == "u" then return true, UDim2.new(v[2], v[3], v[4], v[5]) end if t == "e" then local ok, e = pcall(function() return Enum[v[2]][v[3]] end) if ok and e then return true, e end return false, nil end if t == "cs" then local pts = {} for i = 2, #v do local pair = v[i] if type(pair) == "table" then local ok, col = decValue(pair[2], created) if ok then table.insert(pts, ColorSequenceKeypoint.new(pair[1], col)) end end end if #pts > 0 then return true, ColorSequence.new(pts) end return false, nil end if t == "ns" then local pts = {} for i = 2, #v do local pair = v[i] if type(pair) == "table" then table.insert(pts, NumberSequenceKeypoint.new(pair[1], pair[2], pair[3])) end end if #pts > 0 then return true, NumberSequence.new(pts) end return false, nil end if t == "t" then local out = {} for i = 2, #v do local pair = v[i] if type(pair) == "table" then local okK, k = decValue(pair[1], created) local okV, val = decValue(pair[2], created) if okK and okV and k ~= nil then out[k] = val end end end return true, out end return false, nil end -- Properties worth recording. Unknown/nonexistent ones are simply skipped. local PROP_NAMES = { "CFrame", "Size", "Color", "Color3", "Transparency", "Reflectance", "Metallic", "Material", "Anchored", "CanCollide", "CanTouch", "CastShadow", "CollisionGroup", "Shape", "MeshId", "TextureID", "TextureId", "Scale", "Offset", "MeshType", "VertexColor", "Brightness", "Range", "Enabled", "Shadows", "Angle", "Face", "LightEmission", "LightInfluence", "Texture", "ZIndex", "Image", "ImageColor3", "StudsPerTileU", "StudsPerTileV", "OffsetStudsU", "OffsetStudsV", "ImageRectOffset", "ImageRectSize", "Visible", "Width0", "Width1", "CurveSize0", "CurveSize1", "Segments", "FaceCamera", "Attachment0", "Attachment1", "Part0", "Part1", "C0", "C1", "Length", "MinLength", "MaxLength", "Mass", "Density", "Friction", "Elasticity", "FrictionWeight", "ElasticityWeight", "SoundId", "Volume", "Looped", "Playing", "RenderFidelity", "LocalTransparencyModifier", "Rate", "Lifetime", "Speed", "SpreadAngle", "Acceleration", "RotationSpeed", "EmissionDirection", "AutoDampen", "AutoDisable", "Drag", "AirResistance", "VelocityInheritance", "TimeScale", "CanQuery", "MaterialVariant", "SurfaceColor3", "CollisionFidelity", "DoubleSided", "PrimaryPart", "StudsOffset", "MaxDistance", "AlwaysOnTop", "CanvasSize", "Heat", "ColorSequence", "NumberSequence", "LightColor", "EmissionColor", "ColorMap", "NormalMap", "RoughnessMap", "MetalnessMap", "AlphaMode", "Overlay", "PackManualUVs", "Wireframe", } local SKIP_PROP = { Parent = true, Name = true, ClassName = true, Archivable = true, DataCost = true, Position = true, } local SKIP_CLASS = { Script = true, LocalScript = true, ModuleScript = true, Humanoid = true, Terrain = true, Camera = true, } local function serializePlot(plot) local build = plot:FindFirstChild("Build") if not build then return nil end local srcPivot = getPivot(plot) -- Pass 1: index every object so references can point forward/backward. local all, refs = {}, {} local function skipInst(inst) if SKIP_CLASS[inst.ClassName] or inst.Name == "PlotCopierWeld" then return true end -- Building Tools adds these on every server part. Their Value points -- outside the build, so they only add save size and work. if inst:IsA("ObjectValue") and (inst.Name == "Creator" or inst.Name == "Plot" or inst.Name == "Edit") then return true end return false end local function collect(inst, parentIdx) local idx = #all + 1 refs[inst] = idx table.insert(all, { inst = inst, pi = parentIdx }) -- Yield periodically so a large save never freezes the whole client. if idx % 200 == 0 then task.wait() end for _, child in ipairs(inst:GetChildren()) do if not skipInst(child) then collect(child, idx) end end end for _, child in ipairs(build:GetChildren()) do if not skipInst(child) then collect(child, 0) end end -- Pass 2: encode properties, attributes and part pivots. local items, partCount, wireCount, wireTypes = {}, 0, 0, {} setProgress(0, #all, "scanning " .. #all .. " objects") for idx, rec in ipairs(all) do if idx % 120 == 0 then setProgress(idx, #all, "saving " .. idx .. "/" .. #all) task.wait() end local inst = rec.inst local isBase = inst:IsA("BasePart") if isBase then partCount += 1 end local pr = {} for _, name in ipairs(PROP_NAMES) do if not SKIP_PROP[name] then if not (isBase and (name == "CFrame" or name == "Position")) then local ok, val = pcall(function() return inst[name] end) if ok and val ~= nil then local enc = encValue(val, refs) if enc ~= nil then pr[name] = enc end end end end end if isTexturedWire(inst, pr) then wireCount += 1 local tn = wireTypeNumber(pr) if tn then wireTypes[tn] = (wireTypes[tn] or 0) + 1 end end local e = { i = idx, cn = inst.ClassName, nm = inst.Name, pi = rec.pi, pr = pr } if isBase then local okCF, rel = pcall(function() return srcPivot:Inverse() * inst.CFrame end) if okCF then e.rc = encValue(rel, refs) end end local okAttr, attrs = pcall(function() return inst:GetAttributes() end) if okAttr and type(attrs) == "table" then local at = {} for k, val in pairs(attrs) do local enc = encValue(val, refs) if enc ~= nil then at[k] = enc end end if next(at) then e.at = at end end table.insert(items, e) end lastWireCount = wireCount return HttpService:JSONEncode({ v = CONFIG.SAVE_VERSION, owner = plotOwnerName(plot), count = partCount, wires = wireCount, wireTypes = wireTypes, objects = #items, parts = nil, items = items, }) end -- --------------------------------------------------------------------------- -- Building Tools access (persistent server builds) -- --------------------------------------------------------------------------- -- Building Tools access: only the normal SyncAPI BindableFunction from your -- own tool. No direct remotes, no module hooks, no cloning other players' tools. local function makeApiSync(api) return { IsServer = true, Invoke = function(_, action, ...) return api:Invoke(action, ...) end, } end local function findMyTool() local containers = { LocalPlayer.Backpack } if LocalPlayer.Character then table.insert(containers, LocalPlayer.Character) end table.insert(containers, PlayerGui) for _, container in ipairs(containers) do for _, obj in ipairs(container:GetDescendants()) do if obj:IsA("Tool") and obj.Name:lower():find("building") then return obj end end end return nil end local function getSync() local tool = findMyTool() if not tool then return nil, "no Building Tools in your backpack" end local api = tool:FindFirstChild("SyncAPI") if not api or not api:IsA("BindableFunction") then return nil, "no SyncAPI BindableFunction" end return makeApiSync(api), "SyncAPI" end -- Building Tools CreatePart accepts a type string, not an arbitrary class. local function partTypeFor(cn, props) if cn == "TrussPart" then return "Truss" end if cn == "WedgePart" then return "Wedge" end if cn == "CornerWedgePart" then return "Corner" end if cn == "Seat" then return "Seat" end if cn == "VehicleSeat" then return "Vehicle Seat" end if cn == "SpawnLocation" or cn == "Spawn" then return "Spawn" end local shape = props and props.Shape if typeof(shape) == "EnumItem" then if shape.Name == "Cylinder" then return "Cylinder" end if shape.Name == "Ball" then return "Ball" end end return "Normal" end -- Server actions can be silently dropped while BuildCooling is active. For -- part creation (the one action that must not be skipped) wait it out and retry. local function cooldownActive() return LocalPlayer:FindFirstChild("BuildCooling") ~= nil end local function waitForServerCooldown(maxSeconds) local deadline = os.clock() + (maxSeconds or 5) while cooldownActive() do if stopRequested or os.clock() > deadline then return false end task.wait(0.05) end return not stopRequested end local function asInstance(res) if typeof(res) == "Instance" then return res end if type(res) == "table" and typeof(res[1]) == "Instance" then return res[1] end return nil end local function createPartOnPlot(sync, d, cf, parent) local typeStr = partTypeFor(d.ClassName, d) for attempt = 1, 3 do if cooldownActive() and not waitForServerCooldown() then return nil end local ok, result = pcall(function() return sync:Invoke("CreatePart", typeStr, cf, parent) end) local part = ok and asInstance(result) or nil if part then return part end if attempt < 3 and not waitForServerCooldown() then break end end return nil end local function withTarget(callback) if busy then log("Already working - please wait", true) return end busy = true stopRequested = false local targetPlot, targetBuild = findMyPlot() if not targetPlot then showError("No target plot detected - you need to own/claim a plot in-game") busy = false return end local sync, how = getSync() if not sync then showError("Could not get Building Tools: " .. tostring(how)) busy = false return end log("Using " .. how .. " from your Building Tools") buildRunning = true local ok, err = pcall(callback, targetPlot, targetBuild, sync) buildRunning = false busy = false stopRequested = false setProgress(0, 0, "Ready") if not ok then showError(err) end end -- --------------------------------------------------------------------------- -- Build: v2 (everything) and legacy v1 -- --------------------------------------------------------------------------- local function applyRecord(inst, e, created, pivot) -- Building Tools' SetName action validates but does not always assign, -- especially on server-created Models. Keep the saved name locally too so -- the rebuild matches the source hierarchy on screen. if e.nm and inst.Name ~= e.nm then pcall(function() inst.Name = e.nm end) end if e.pr then for name, enc in pairs(e.pr) do local okV, val = decValue(enc, created) if okV then pcall(function() inst[name] = val end) end end end if e.rc and inst:IsA("BasePart") then local okV, rel = decValue(e.rc, created) if okV then pcall(function() inst.CFrame = pivot * rel end) end end if e.at then for k, enc in pairs(e.at) do local okV, val = decValue(enc, created) if okV then pcall(function() inst:SetAttribute(k, val) end) end end end end -- Decode a saved record's tagged properties without applying them yet. local function decodeRecordProps(e, created) local out = {} if type(e.pr) == "table" then for name, enc in pairs(e.pr) do local ok, val = decValue(enc, created) if ok then out[name] = val end end end return out end local function recordCFrame(e, created, pivot) local cf = pivot if type(e.rc) == "table" and e.rc[1] == "c" then local ok, rel = decValue(e.rc, created) if ok and typeof(rel) == "CFrame" then cf = pivot * rel end end return cf end local function isPartClass(cn) return type(cn) == "string" and (cn == "Part" or cn:find("Part$") or cn == "Seat" or cn == "VehicleSeat" or cn == "SpawnLocation") end local function firstInstance(res) if typeof(res) == "Instance" then return res end if type(res) == "table" and typeof(res[1]) == "Instance" then return res[1] end return nil end local function allInstances(res) local out = {} if typeof(res) == "Instance" then table.insert(out, res) elseif type(res) == "table" then for _, v in ipairs(res) do if typeof(v) == "Instance" then table.insert(out, v) end end end return out end local function serverInvoke(sync, action, ...) local args = { ... } -- Creation actions are dropped while BuildCooling is active; other actions -- return nil on success, so only creations get the pre-flight cooldown wait. if tostring(action):find("^Create") and cooldownActive() and not waitForServerCooldown() then return false, "cooldown" end local ok, result = pcall(function() return sync:Invoke(action, unpackFn(args)) end) if not ok then log("Server " .. action .. " failed: " .. tostring(result), true) end return ok, result end -- A server invoke costs roughly 50ms on this game. Building Tools' property -- actions accept arrays, so a whole chunk can be applied in a few calls instead -- of one call per part. SyncResize is the exception: its per-part Values map is -- keyed by Instance and those keys do not survive the RemoteFunction boundary. -- Each resize payload therefore carries one scalar Size for a group of parts -- that share that value. Groups accumulate across chunks so the ~3000 unique -- axis values in a large save become ~3000 invokes instead of ~13,000. A single -- value can belong to thousands of parts, so each group is also sent in bounded -- 100-part pieces; one huge invoke was the cause of the missing sizes. -- SetName is intentionally not used: the tool only validates it and never -- assigns the name, so the local name assignment is the real fix. local BATCH_CHUNK = 100 local RESIZE_FLUSH_CHUNK = 100 local RESIZE_PART_CHUNK = 100 -- Child objects (lights/textures/meshes) are also created through array -- actions. Keep each batch small and unique per parent/face because Building -- Tools silently deduplicates repeated parent (and parent+face) keys. local CHILD_BATCH_CHUNK = 50 local AXES = { "X", "Y", "Z" } local function newPropertyBatch() return { color = {}, material = {}, collision = {}, surface = {}, moves = {}, resize = { X = { Groups = {} }, Y = { Groups = {} }, Z = { Groups = {} }, }, resizeGroupCount = 0, parents = {}, } end local function clearResizeGroups(batch) for _, axis in ipairs(AXES) do batch.resize[axis].Groups = {} end batch.resizeGroupCount = 0 end local function clearPropertyBatch(batch) batch.color, batch.material, batch.collision = {}, {}, {} batch.surface, batch.moves, batch.parents = {}, {}, {} end local function batchPending(batch) local n = #batch.color + #batch.material + #batch.collision + #batch.surface + #batch.moves for _, kids in pairs(batch.parents) do n = n + #kids end return n end local function resizeBatchReady(batch, force) if force or batch.resizeGroupCount >= RESIZE_FLUSH_CHUNK then return true end for _, axis in ipairs(AXES) do for _, group in pairs(batch.resize[axis].Groups) do if #group.Parts >= RESIZE_PART_CHUNK then return true end end end return false end local function flushResizeGroups(sync, batch, force) if not sync or not sync.IsServer or batch.resizeGroupCount == 0 then return true end if not resizeBatchReady(batch, force) then return true end if not waitForServerCooldown(8) then return false end for _, axis in ipairs(AXES) do for _, group in pairs(batch.resize[axis].Groups) do for i = 1, #group.Parts, RESIZE_PART_CHUNK do local chunk = {} for j = i, math.min(i + RESIZE_PART_CHUNK - 1, #group.Parts) do chunk[#chunk + 1] = group.Parts[j] end if #chunk > 0 then serverInvoke(sync, "SyncResize", { Type = "SetSize", Axis = axis, Parts = chunk, Size = group.Value, }) end end end end clearResizeGroups(batch) return true end local function flushPropertyBatch(sync, batch, force) if not sync or not sync.IsServer then return true end local pending = batchPending(batch) local resizeReady = batch.resizeGroupCount > 0 and resizeBatchReady(batch, force) if pending == 0 and not resizeReady then return true end if pending > 0 and not waitForServerCooldown(8) then return false end if #batch.color > 0 then serverInvoke(sync, "SyncColor", batch.color) end if #batch.material > 0 then serverInvoke(sync, "SyncMaterial", batch.material) end if #batch.surface > 0 then serverInvoke(sync, "SyncSurface", batch.surface) end if #batch.collision > 0 then serverInvoke(sync, "SyncCollision", batch.collision) end for parent, kids in pairs(batch.parents) do if parent and #kids > 0 then serverInvoke(sync, "SetParent", kids, parent) end end for _, mv in ipairs(batch.moves) do serverInvoke(sync, "SyncMove", mv) end -- Do not verify here: the client view can lag the server invoke by a -- network tick and would report false failures. The final local property -- pass restores every saved value even if the tool drops an action. clearPropertyBatch(batch) return flushResizeGroups(sync, batch, force) end -- Queue a record's server-side properties instead of invoking one at a time. local function serverApplyRecord(sync, inst, e, props, created, pivot, cf, batch) if not inst or not inst.Parent then return end batch = batch or newPropertyBatch() if e.nm and inst.Name ~= e.nm then pcall(function() inst.Name = e.nm end) end if inst:IsA("BasePart") then if props.Color ~= nil then table.insert(batch.color, { Part = inst, Color = props.Color, UnionColoring = false }) end if props.Material ~= nil or props.Transparency ~= nil or props.Reflectance ~= nil or props.CastShadow ~= nil or props.MaterialVariant ~= nil then local payload = { Part = inst } for _, key in ipairs({ "Material", "MaterialVariant", "Transparency", "Reflectance", "CastShadow" }) do if props[key] ~= nil then payload[key] = props[key] end end table.insert(batch.material, payload) end if props.Size ~= nil then for _, axis in ipairs(AXES) do local value = axis == "X" and props.Size.X or axis == "Y" and props.Size.Y or props.Size.Z local key = tostring(value) local groups = batch.resize[axis].Groups local group = groups[key] if not group then group = { Value = value, Parts = {} } groups[key] = group batch.resizeGroupCount += 1 end table.insert(group.Parts, inst) end end local surfaces = {} for _, side in ipairs({ "Top", "Bottom", "Left", "Right", "Front", "Back" }) do local value = props[side .. "Surface"] if typeof(value) == "EnumItem" and value.EnumType == Enum.SurfaceType then surfaces[side] = value end end if next(surfaces) then table.insert(batch.surface, { Part = inst, Surfaces = surfaces }) end if props.CanCollide ~= nil then table.insert(batch.collision, { Part = inst, CanCollide = props.CanCollide }) end -- CreatePart already applies the exact CFrame server-side. Reading it -- here sees the pre-replication client copy, so a drift check only -- generates hundreds of pointless SyncMove invokes. The final local -- restore pass sets every saved CFrame exactly, so no move is needed. end if e.pi and e.pi > 0 then local parent = created[e.pi] if parent and parent ~= inst then batch.parents[parent] = batch.parents[parent] or {} table.insert(batch.parents[parent], inst) end end end -- Child objects that Building Tools can create on the server. local function serverCreateChild(sync, e, props, created) local cn = e.cn local parent = (e.pi and e.pi > 0) and created[e.pi] or nil if not parent or not parent:IsA("BasePart") then return nil end if cn == "PointLight" or cn == "SpotLight" or cn == "SurfaceLight" then local _, res = serverInvoke(sync, "CreateLights", { { Part = parent, LightType = cn } }) local light = firstInstance(res) if light then local data = { Part = parent, LightType = cn } for _, key in ipairs({ "Range", "Brightness", "Color", "Shadows", "Face", "Angle" }) do if props[key] ~= nil then data[key] = props[key] end end serverInvoke(sync, "SyncLighting", { data }) end return light end if cn == "Decal" or cn == "Texture" then local face = props.Face if typeof(face) ~= "EnumItem" or face.EnumType ~= Enum.NormalId then face = Enum.NormalId.Top end local _, res = serverInvoke(sync, "CreateTextures", { { Part = parent, Face = face, TextureType = cn, } }) local tex = firstInstance(res) if tex then local data = { Part = parent, Face = face, TextureType = cn } for _, key in ipairs({ "Texture", "Transparency", "StudsPerTileU", "StudsPerTileV", "OffsetStudsU", "OffsetStudsV", "Color3" }) do if props[key] ~= nil then data[key] = props[key] end end serverInvoke(sync, "SyncTexture", { data }) end return tex end if cn == "SpecialMesh" or cn == "DataModelMesh" then local _, res = serverInvoke(sync, "CreateMeshes", { { Part = parent } }) local mesh = firstInstance(res) if mesh then local data = { Part = parent } for _, key in ipairs({ "VertexColor", "MeshType", "Scale", "Offset", "MeshId" }) do if props[key] ~= nil then data[key] = props[key] end end local texId = props.TextureId or props.TextureID if texId ~= nil then data.TextureId = texId end serverInvoke(sync, "SyncMesh", { data }) end return mesh end -- The game's "texture tool" stores maps in a SurfaceAppearance child. if cn == "SurfaceAppearance" then if not parent:IsA("MeshPart") then return nil end local _, res = serverInvoke(sync, "CreateSurfaceAppearances", { { Part = parent } }) local sa = firstInstance(res) if sa then if props.TextureID ~= nil then serverInvoke(sync, "SyncSurfaceAppearance", { { Part = parent, TextureID = props.TextureID, } }) end for _, key in ipairs({ "ColorMap", "NormalMap", "RoughnessMap", "MetalnessMap" }) do if props[key] ~= nil then serverInvoke(sync, "SyncSurfaceAppearance", { { Part = parent, SAProperty = key, Value = props[key], } }) end end end return sa end return nil end local function isWireClass(cn) if type(cn) ~= "string" then return false end if cn == "Attachment" or cn == "Beam" or cn == "Weld" or cn == "WeldConstraint" then return true end return cn:find("Constraint$") ~= nil end local function buildFromData(dataStr, targetPlot, targetBuild, sync) local ok, data = pcall(HttpService.JSONDecode, HttpService, dataStr) if not ok or type(data) ~= "table" then showError("invalid save data") return false end if data.v == CONFIG.SAVE_VERSION and type(data.items) == "table" then local items = data.items local pivot = getPivot(targetPlot) local total = #items local created, skipped, parts = {}, {}, {} local lights, wired, texturedWires, builtWireTypes = 0, 0, 0, {} local wireHosts, wireModels = {}, {} -- A wire only works when its host part's direct parent is a Model. Find -- every Model that contains (or ancestors) a saved wire before building, -- so those Models can be created with the server's CreateGroup action -- instead of a local Model that would never replicate. for idx, e in ipairs(items) do if recordIsWireTexture(e) then local hostIdx = e.pi if hostIdx and items[hostIdx] then wireHosts[hostIdx] = true local m = items[hostIdx].pi while m and m > 0 and items[m] do wireModels[m] = true m = items[m].pi end end end end log("Rebuilding " .. total .. " objects (" .. tostring(data.count or 0) .. " parts)...") local isServer = sync and sync.IsServer and CONFIG.SERVER_BUILD setProgress(0, total, progressText(0, total, isServer ~= nil)) if isServer then log("Server build: " .. speedName() .. " random delay per part") end local lastPartAt = 0 local stoppedEarly = false local batch = isServer and newPropertyBatch() or nil local sinceFlush = 0 local pendingParts = {} local childJobs, childJobByIndex = {}, {} -- A marker holds the slot until its CreatePart invoke returns. Nothing -- may use it as an Instance before resolvePendingAt has run. local function resolvePendingAt(idx) local v = created[idx] if type(v) ~= "table" or not v.__pendingCreate then return v end local deadline = os.clock() + 30 while not v.done and os.clock() < deadline do if stopRequested then break end task.wait(0.02) end if v.done and not v.inst then v.inst = createPartOnPlot(sync, v.partData, v.cf, targetBuild) end created[idx] = v.inst return v.inst end local function finishPartWindow() if #pendingParts == 0 then return true end for _, job in ipairs(pendingParts) do local inst = resolvePendingAt(job.idx) if inst then table.insert(parts, inst) if isTexturedWire(inst, job.props) then texturedWires += 1 local tn = wireTypeNumber(job.props) if tn then builtWireTypes[tn] = (builtWireTypes[tn] or 0) + 1 end end if isWireClass(job.e.cn) then wired += 1 end serverApplyRecord(sync, inst, job.e, job.props, created, pivot, job.cf, batch) sinceFlush += 1 if sinceFlush >= BATCH_CHUNK then if not flushPropertyBatch(sync, batch) then return false end sinceFlush = 0 log(string.format("Applied properties for %d/%d objects", job.idx, total)) end end end pendingParts = {} return true end -- Batch the leaf objects that Building Tools can create by array. -- They are leaves in normal saves, but the round-based flush also -- handles a child whose parent is another queued child. local function noteChildResult(job, inst) if not inst then return false end created[job.idx] = inst if isTexturedWire(inst, job.props) then texturedWires += 1 local tn = wireTypeNumber(job.props) if tn then builtWireTypes[tn] = (builtWireTypes[tn] or 0) + 1 end end if isWireClass(job.e.cn) then wired += 1 end if job.group == "light" and inst:IsA("Light") then lights += 1 end return true end local function childKey(job, parent) if job.group == "texture" then return tostring(parent) .. "|" .. tostring(job.face and job.face.Name) end return parent end local function takeUniqueChildJobs(jobs) local chosen, rest, seen = {}, {}, {} for _, job in ipairs(jobs) do local parent = created[job.pi] local key = (parent and parent:IsA("BasePart")) and childKey(job, parent) or nil if key and not seen[key] and #chosen < CHILD_BATCH_CHUNK then table.insert(chosen, job) seen[key] = true else table.insert(rest, job) end end return chosen, rest end local function processChildGroup(jobs, group, createAction, syncAction) while #jobs > 0 do local chosen, rest = takeUniqueChildJobs(jobs) if #chosen == 0 then break end local createPayload, meta = {}, {} for _, job in ipairs(chosen) do local payload = { Part = created[job.pi] } if group == "texture" then payload.Face = job.face payload.TextureType = job.e.cn elseif group == "light" then payload.LightType = job.e.cn end table.insert(createPayload, payload) meta[payload] = job end if not waitForServerCooldown(8) then return jobs end local _, res = serverInvoke(sync, createAction, createPayload) local byKey = {} for _, inst in ipairs(allInstances(res)) do local parent = inst.Parent if parent then if group == "texture" then if inst:IsA("Texture") or inst:IsA("Decal") then byKey[tostring(parent) .. "|" .. tostring(inst.Face and inst.Face.Name)] = inst end elseif group == "light" then byKey[parent] = inst elseif group == "mesh" and inst:IsA("SpecialMesh") then byKey[parent] = inst end end end local syncPayload = {} for _, job in ipairs(chosen) do local parent = created[job.pi] local inst = byKey[childKey(job, parent)] if not inst then local okNew, newInst = pcall(Instance.new, job.e.cn) if okNew and parent then newInst.Parent = parent inst = newInst end end if noteChildResult(job, inst) then local data = { Part = parent } if group == "texture" then data.Face = job.face data.TextureType = job.e.cn for _, key in ipairs({ "Texture", "Transparency", "StudsPerTileU", "StudsPerTileV", "OffsetStudsU", "OffsetStudsV", "Color3" }) do if job.props[key] ~= nil then data[key] = job.props[key] end end elseif group == "light" then data.LightType = job.e.cn for _, key in ipairs({ "Range", "Brightness", "Color", "Shadows", "Face", "Angle" }) do if job.props[key] ~= nil then data[key] = job.props[key] end end else for _, key in ipairs({ "VertexColor", "MeshType", "Scale", "Offset", "MeshId" }) do if job.props[key] ~= nil then data[key] = job.props[key] end end local texId = job.props.TextureId or job.props.TextureID if texId ~= nil then data.TextureId = texId end end table.insert(syncPayload, data) end end if #syncPayload > 0 then serverInvoke(sync, syncAction, syncPayload) end jobs = rest end return jobs end local function flushChildBatches() if #childJobs == 0 then return true end local all = childJobs childJobs, childJobByIndex = {}, {} local groups = { { group = "light", action = "CreateLights", sync = "SyncLighting", jobs = {} }, { group = "texture", action = "CreateTextures", sync = "SyncTexture", jobs = {} }, { group = "mesh", action = "CreateMeshes", sync = "SyncMesh", jobs = {} }, } for _, job in ipairs(all) do table.insert(groups[job.groupIndex].jobs, job) end local leftover = {} for _, g in ipairs(groups) do local rest = processChildGroup(g.jobs, g.group, g.action, g.sync) for _, job in ipairs(rest) do table.insert(leftover, job) end end -- Unresolved parents are rare; keep the old one-at-a-time path as a -- safety net instead of dropping the object. for _, job in ipairs(leftover) do local inst = serverCreateChild(sync, job.e, job.props, created) if not inst then local okNew, newInst = pcall(Instance.new, job.e.cn) if okNew then newInst.Parent = created[job.pi] or targetBuild inst = newInst end end noteChildResult(job, inst) end log("Batched " .. #all .. " child objects") return true end for i, e in ipairs(items) do if stopRequested then stoppedEarly = true break end local props = decodeRecordProps(e, created) local cf = recordCFrame(e, created, pivot) local partLike = isPartClass(e.cn) -- If this record hangs off a deferred child object, resolve those -- children first so their Instance is available as a parent. if isServer and e.pi and childJobByIndex[e.pi] and not created[e.pi] then if not flushChildBatches() then stoppedEarly = true break end end if partLike and isServer then if lastPartAt > 0 then local delay = buildDelay() local target = lastPartAt + delay local remaining = target - os.clock() if remaining > 0 then if i == 1 or i % 250 == 0 then log(string.format("Waiting %.2fs before part %d/%d", remaining, i, total)) end if not waitWithStop(remaining) then stoppedEarly = true break end end end if not waitForCooling() then if stopRequested then stoppedEarly = true end break end elseif partLike and not waitForCooling() then if stopRequested then stoppedEarly = true end break end if stopRequested then stoppedEarly = true break end local inst = nil local parallelPart = partLike and isServer and CONFIG.PARALLEL_CREATE if parallelPart then local partData = { ClassName = e.cn, Name = props.Name or e.nm or "Part", Shape = props.Shape, Color = props.Color or props.Color3, Material = props.Material, Size = props.Size, Transparency = props.Transparency, Reflectance = props.Reflectance, Anchored = props.Anchored, CanCollide = props.CanCollide, } local marker = { __pendingCreate = true, done = false, inst = nil, partData = partData, cf = cf, } created[i] = marker table.insert(pendingParts, { idx = i, e = e, props = props, cf = cf }) task.spawn(function() local part = createPartOnPlot(sync, partData, cf, targetBuild) marker.inst = part marker.done = true end) lastPartAt = os.clock() if #pendingParts >= CONFIG.CREATE_WINDOW then if not finishPartWindow() then stoppedEarly = true break end end elseif partLike then inst = createPartOnPlot(sync, { ClassName = e.cn, Name = props.Name or e.nm or "Part", Shape = props.Shape, Color = props.Color or props.Color3, Material = props.Material, Size = props.Size, Transparency = props.Transparency, Reflectance = props.Reflectance, Anchored = props.Anchored, CanCollide = props.CanCollide, }, cf, targetBuild) end local parentForChild = (e.pi and e.pi > 0) and resolvePendingAt(e.pi) or targetBuild -- Wire Models are deferred to the server group pass below. Making -- them locally would only reparent parts on this client, and the -- game's wiring scan runs from the server's hierarchy. local deferredGroup = isServer and e.cn == "Model" and wireModels[i] == true if not deferredGroup and not parallelPart then local queuedChild = false if not inst and isServer then local groupIndex if e.cn == "PointLight" or e.cn == "SpotLight" or e.cn == "SurfaceLight" then groupIndex = 1 elseif e.cn == "Texture" or e.cn == "Decal" then groupIndex = 2 elseif e.cn == "SpecialMesh" or e.cn == "DataModelMesh" then groupIndex = 3 end if groupIndex and parentForChild and parentForChild:IsA("BasePart") then local face = nil if groupIndex == 2 then face = props.Face if typeof(face) ~= "EnumItem" or face.EnumType ~= Enum.NormalId then face = Enum.NormalId.Top end end table.insert(childJobs, { idx = i, e = e, props = props, pi = e.pi, groupIndex = groupIndex, face = face, group = groupIndex == 1 and "light" or groupIndex == 2 and "texture" or "mesh", }) childJobByIndex[i] = true queuedChild = true else inst = serverCreateChild(sync, e, props, created) end end if not inst and not queuedChild then -- Roblox only allows SurfaceAppearance under a MeshPart. This -- Building Tools version cannot server-create MeshParts, so -- skip instead of throwing when the rebuilt parent is a Part. if e.cn == "SurfaceAppearance" and (not parentForChild or not parentForChild:IsA("MeshPart")) then skipped["SurfaceAppearance(no MeshPart)"] = (skipped["SurfaceAppearance(no MeshPart)"] or 0) + 1 else local okNew, newInst = pcall(Instance.new, e.cn) if okNew then inst = newInst end end end if not inst and not queuedChild then skipped[tostring(e.cn)] = (skipped[tostring(e.cn)] or 0) + 1 elseif inst then created[i] = inst end end if inst then if partLike and isServer then -- Time the gap from the actual part creation, not from the -- property actions that follow it. lastPartAt = os.clock() end if inst:IsA("BasePart") then table.insert(parts, inst) end if isTexturedWire(inst, props) then texturedWires += 1 local tn = wireTypeNumber(props) if tn then builtWireTypes[tn] = (builtWireTypes[tn] or 0) + 1 end end -- Restore the saved wires/constraints themselves instead of -- inventing a generic star weld between every part. if isWireClass(e.cn) then wired += 1 end if inst:IsA("PointLight") or inst:IsA("SpotLight") or inst:IsA("SurfaceLight") then lights += 1 end if isServer and partLike then serverApplyRecord(sync, inst, e, props, created, pivot, cf, batch) sinceFlush += 1 if sinceFlush >= BATCH_CHUNK then if not flushPropertyBatch(sync, batch) then stoppedEarly = true break end sinceFlush = 0 log(string.format("Applied properties for %d/%d objects", i, total)) end end end -- 43k log lines and GUI updates are themselves a major cost. if i == 1 or i % 250 == 0 or i == total then log(string.format("Created %d/%d objects", i, total)) end if i == 1 or i % 25 == 0 or i == total then setProgress(i, total, progressText(i, total, isServer ~= nil)) end if not isServer and not waitWithStop(buildDelay()) then stoppedEarly = true break end end -- Resolve any final partial window, including after a STOP, so no -- created part is left untracked or unstyled. if not finishPartWindow() then stoppedEarly = true end -- A server create can be rejected transiently even after three tries. -- Retry those few records sequentially before grouping so a saved part -- is never silently dropped from the rebuild. local recovered = 0 if isServer and not stoppedEarly then for i, e in ipairs(items) do if stopRequested then stoppedEarly = true break end if not created[i] and isPartClass(e.cn) then local props = decodeRecordProps(e, created) local cf = recordCFrame(e, created, pivot) local inst = createPartOnPlot(sync, { ClassName = e.cn, Name = props.Name or e.nm or "Part", Shape = props.Shape, Color = props.Color or props.Color3, Material = props.Material, Size = props.Size, Transparency = props.Transparency, Reflectance = props.Reflectance, Anchored = props.Anchored, CanCollide = props.CanCollide, }, cf, targetBuild) if inst then created[i] = inst recovered += 1 table.insert(parts, inst) if isTexturedWire(inst, props) then texturedWires += 1 local tn = wireTypeNumber(props) if tn then builtWireTypes[tn] = (builtWireTypes[tn] or 0) + 1 end end if isWireClass(e.cn) then wired += 1 end serverApplyRecord(sync, inst, e, props, created, pivot, cf, batch) sinceFlush += 1 if sinceFlush >= BATCH_CHUNK then if not flushPropertyBatch(sync, batch) then stoppedEarly = true break end sinceFlush = 0 end end end end end if recovered > 0 then log("Recovered " .. recovered .. " rejected part creates") end if isServer and not stoppedEarly and not flushChildBatches() then stoppedEarly = true end -- Build wire-host Models on the server. CreateGroup reparents the -- selected children into a new Model that exists for everyone; a local -- Model would only change this client's hierarchy and the game's wiring -- scan would never see it. local groupsCreated, groupsFailed = 0, 0 local serverGroups, reparentTo = {}, {} if not stoppedEarly and isServer then -- Finish the last chunk before CreateGroup reparents these parts. if not flushPropertyBatch(sync, batch, true) then stoppedEarly = true end local childrenByParent = {} for j, child in ipairs(items) do local p = child.pi or 0 childrenByParent[p] = childrenByParent[p] or {} table.insert(childrenByParent[p], j) end local order = {} for idx in pairs(wireModels) do table.insert(order, idx) end -- Saves are pre-order, so higher indices are deeper nested Models. table.sort(order, function(a, b) return a > b end) for _, idx in ipairs(order) do if stopRequested then stoppedEarly = true break end local e = items[idx] local selection = {} for _, j in ipairs(childrenByParent[idx] or {}) do if created[j] then table.insert(selection, created[j]) end end if #selection > 0 then local parent = (e.pi and e.pi > 0) and created[e.pi] or targetBuild -- Only a server-created Model is a valid CreateGroup parent. -- If an ancestor group failed, attach here directly instead. if not parent or (parent ~= targetBuild and not serverGroups[parent]) then parent = targetBuild end local ok, res = serverInvoke(sync, "CreateGroup", "Model", parent, selection) local group = ok and firstInstance(res) or nil if group then created[idx] = group serverGroups[group] = true groupsCreated += 1 if e.nm then pcall(function() group.Name = e.nm end) end applyRecord(group, e, created, pivot) else groupsFailed += 1 local localGroup = Instance.new("Model") localGroup.Name = e.nm or "Model" localGroup.Parent = parent created[idx] = localGroup end setProgress(idx, total, "grouping " .. groupsCreated .. "/" .. #order) end end -- Safety net: a wire part outside any saved Model still needs a -- group with a sibling, otherwise the game will not scan it. for hostIdx in pairs(wireHosts) do if stopRequested then stoppedEarly = true break end local h = items[hostIdx] local modelIdx = h and h.pi local inModel = modelIdx and modelIdx > 0 and items[modelIdx] and items[modelIdx].cn == "Model" if not inModel then local host = created[hostIdx] local sibling, siblingIdx = nil, nil if h and host and host:IsA("BasePart") then for j, child in ipairs(items) do if j ~= hostIdx and child.pi == h.pi and created[j] and created[j]:IsA("BasePart") then sibling = created[j] siblingIdx = j break end end end if host and sibling then local ok, res = serverInvoke(sync, "CreateGroup", "Model", targetBuild, { host, sibling }) local group = ok and firstInstance(res) or nil if group then groupsCreated += 1 serverGroups[group] = true -- The normal parent pass runs after grouping. Without -- these redirects it would put the pair back under -- Build and leave only an empty group behind. reparentTo[hostIdx] = group reparentTo[siblingIdx] = group pcall(function() group.Name = "WireGroup" end) else groupsFailed += 1 end end end end log("Rebuilt " .. groupsCreated .. " wire-host groups server-side" .. (groupsFailed > 0 and " (" .. groupsFailed .. " failed)" or "")) end -- Parent first (so references resolve), then restore properties. if not stoppedEarly then for i, e in ipairs(items) do local inst = created[i] if inst then local parent = reparentTo[i] if not parent then parent = (e.pi == 0) and targetBuild or created[e.pi] end if not parent then parent = targetBuild end pcall(function() inst.Parent = parent end) end end for i, e in ipairs(items) do local inst = created[i] if inst then applyRecord(inst, e, created, pivot) end if i == 1 or i % 100 == 0 or i == total then setProgress(i, total, "restoring " .. i .. "/" .. total) end end end if isServer and batch then flushPropertyBatch(sync, batch, true) end local wt = {} for _, n in ipairs({ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }) do if builtWireTypes[n] then table.insert(wt, "T" .. n .. ":" .. builtWireTypes[n]) end end log("Restored " .. texturedWires .. " wire textures (exact IDs/speeds/colors)" .. (#wt > 0 and " [" .. table.concat(wt, " ") .. "]" or "")) log("Restored " .. wired .. " saved wires/constraints" .. (wired > 0 and " (client-side where needed)" or "")) local n = 0 for _, inst in pairs(created) do if inst then n += 1 end end local extra = "" local sk = {} for cn, count in pairs(skipped) do table.insert(sk, cn .. "x" .. count) end if #sk > 0 then extra = " (skipped: " .. table.concat(sk, ", ") .. ")" end if stoppedEarly then setProgress(n, total, "stopped") log("Stopped - " .. n .. " objects were created before cancel" .. extra) else setProgress(total, total, n .. " objects") log("Done - " .. n .. " objects restored (" .. lights .. " lights, " .. groupsCreated .. " wire groups)" .. extra) end return n > 0 end -- Legacy v1 save (short keys, parts only) if type(data.parts) ~= "table" then showError("unrecognized save data") return false end local pivot = getPivot(targetPlot) local total = #data.parts local created, partList, wired = 0, {}, 0 local lastPartAt = 0 local stoppedEarly = false local batch = sync.IsServer and newPropertyBatch() or nil local sinceFlush, legacyExpected = 0, {} log("Rebuilding " .. total .. " legacy saved parts...") setProgress(0, total, progressText(0, total, sync.IsServer == true)) for i, e in ipairs(data.parts) do if stopRequested then stoppedEarly = true break end if sync.IsServer and lastPartAt > 0 then local delay = buildDelay() local remaining = (lastPartAt + delay) - os.clock() if remaining > 0 then log(string.format("Waiting %.2fs before legacy part %d/%d", remaining, i, total)) if not waitWithStop(remaining) then stoppedEarly = true break end end end if not waitForCooling() then if stopRequested then stoppedEarly = true end break end if stopRequested then stoppedEarly = true break end local okCF, relCF = pcall(function() return CFrame.new(unpackFn(e.cf)) end) if okCF then local sz = e.sz or { 4, 1, 4 } local cl = e.cl or { 1, 1, 1 } local d = { ClassName = e.cn or "Part", Name = e.nm or "Part", Size = Vector3.new(sz[1], sz[2], sz[3]), Color = Color3.new(cl[1], cl[2], cl[3]), Material = Enum.Material[e.mt or "Plastic"] or Enum.Material.Plastic, Transparency = e.tr or 0, Reflectance = e.rf or 0, Anchored = true, CanCollide = e.cc ~= false, } if e.sh then d.Shape = Enum.PartType[e.sh] or Enum.PartType.Block end if e.mi then d.MeshId = e.mi end if e.tx then d.TextureID = e.tx end local part = createPartOnPlot(sync, d, pivot * relCF, targetBuild) if part then created += 1 if e.nm then pcall(function() part.Name = e.nm end) end if sync.IsServer then lastPartAt = os.clock() end table.insert(partList, part) if sync.IsServer then legacyExpected[part] = d table.insert(batch.color, { Part = part, Color = d.Color }) table.insert(batch.material, { Part = part, Material = d.Material, Transparency = d.Transparency, Reflectance = d.Reflectance, }) for _, axis in ipairs(AXES) do local value = axis == "X" and d.Size.X or axis == "Y" and d.Size.Y or d.Size.Z local key = tostring(value) local groups = batch.resize[axis].Groups local group = groups[key] if not group then group = { Value = value, Parts = {} } groups[key] = group batch.resizeGroupCount += 1 end table.insert(group.Parts, part) end if d.CanCollide ~= nil then table.insert(batch.collision, { Part = part, CanCollide = d.CanCollide }) end sinceFlush += 1 if sinceFlush >= BATCH_CHUNK then if not flushPropertyBatch(sync, batch) then stoppedEarly = true break end sinceFlush = 0 end end end end if i == 1 or i % 25 == 0 or i == total then log(string.format("Placed %d/%d saved parts", i, total)) setProgress(i, total, progressText(i, total, sync.IsServer == true)) end if not sync.IsServer and not waitWithStop(buildDelay()) then stoppedEarly = true break end end if sync.IsServer and batch then flushPropertyBatch(sync, batch, true) -- Last-resort local fix if the tool silently rejected a property. for part, d in pairs(legacyExpected) do pcall(function() if part.Color ~= d.Color then part.Color = d.Color end if part.Material ~= d.Material then part.Material = d.Material end if part.Transparency ~= d.Transparency then part.Transparency = d.Transparency end if part.Reflectance ~= d.Reflectance then part.Reflectance = d.Reflectance end if part.CanCollide ~= d.CanCollide then part.CanCollide = d.CanCollide end if part.Size ~= d.Size then part.Size = d.Size end end) end end log("Legacy v1 save has no wire/constraint data to restore") if stoppedEarly then setProgress(created, total, "stopped") log("Stopped - " .. created .. " legacy parts were created before cancel") else setProgress(total, total, created .. " parts") log("Done - " .. created .. " legacy parts created") end return created > 0 end -- --------------------------------------------------------------------------- -- Save / saved-base helpers -- --------------------------------------------------------------------------- local function savePlot(entry) local dataStr = serializePlot(entry.plot) if not dataStr then showError("plot has no Build folder") return end -- JSONEncode already validates the table tree. Decoding the whole string a -- second time was the main source of save lag, so do a cheap sanity check. if #dataStr < 16 or dataStr:sub(1, 1) ~= "{" or not dataStr:find('"items"', 1, true) then showError("serialization check failed - save aborted") return end -- Keep the full (possibly >200k char) JSON out of any TextBox. -- The clipboard can stall on very large strings; defer it off the click. task.defer(function() pcall(setclipboard, dataStr) end) setProgress(0, 1, "writing save file") fsMakeFolder(CONFIG.SAVE_FOLDER) local safe = entry.name:gsub("[^%w_]", "_") local path = CONFIG.SAVE_FOLDER .. "/base_" .. safe .. ".json" local ok, err = fsWrite(path, dataStr) local summary = string.format( "Saved %s -> %s (%d parts / %d objects / %d wires / %d chars; clipboard + file)", entry.name, path, entry.parts, entry.objects or entry.parts, lastWireCount, #dataStr) if ok then log(summary) else log(summary .. " [file failed: " .. tostring(err) .. "]", true) end end local function getSavedBases() fsMakeFolder(CONFIG.SAVE_FOLDER) local out = {} local ok, files = fsList(CONFIG.SAVE_FOLDER) if ok then for _, path in ipairs(files) do local fileName = path:match("([^/\\]+)$") or path if fileName:lower():find("^base_") and fileName:lower():find("%.json$") then local okRead, content = fsRead(path) if okRead then local okDec, data = pcall(HttpService.JSONDecode, HttpService, content) local name = (okDec and data.owner) or (path:match("([^/\\]+)$") or path) local count = okDec and (data.count or (type(data.parts) == "table" and #data.parts or 0)) or 0 table.insert(out, { path = path, name = tostring(name), count = count }) end end end end table.sort(out, function(a, b) return a.name < b.name end) return out end local function buildSaved(record) withTarget(function(targetPlot, targetBuild, sync) local okRead, content = fsRead(record.path) if not okRead then showError("Could not read save: " .. tostring(content)) return end buildFromData(content, targetPlot, targetBuild, sync) end) end local function clearMyPlot() withTarget(function(_, targetBuild, sync) local kids = targetBuild:GetChildren() local total = #kids local removed, stoppedEarly = 0, false local chunk = {} -- Remove accepts an array. One invoke per 100 children avoids tens of -- thousands of round trips on a large plot while staying a normal -- Building Tools action with no cooldown bypass. local function flushRemoves() if #chunk == 0 then return true end if not waitForServerCooldown(8) then return false end serverInvoke(sync, "Remove", chunk) removed += #chunk chunk = {} setProgress(removed, total, "clearing " .. removed .. "/" .. total) return waitWithStop(0.05) end for _, child in ipairs(kids) do if stopRequested then stoppedEarly = true break end table.insert(chunk, child) if #chunk >= BATCH_CHUNK then if not flushRemoves() then stoppedEarly = true break end end end if not stoppedEarly and not flushRemoves() then stoppedEarly = true end if stoppedEarly then log("Clearing stopped - " .. removed .. " objects removed") else -- Clean any stale child left in the local view so "clear" always -- leaves an empty plot on screen. task.wait(0.25) for _, child in ipairs(targetBuild:GetChildren()) do pcall(function() child:Destroy() end) end log("Cleared " .. removed .. " objects from your plot (server)") end end) end local function buildLive(entry) local target = findMyPlot() if target and entry.plot == target then showError("That is already your plot - pick another one") return end withTarget(function(targetPlot, targetBuild, sync) log("Building " .. entry.name .. "'s plot onto yours...") local dataStr = serializePlot(entry.plot) if not dataStr then showError("source has no Build folder") return end buildFromData(dataStr, targetPlot, targetBuild, sync) end) end -- --------------------------------------------------------------------------- -- GUI -- --------------------------------------------------------------------------- local function makeGui() if PlayerGui:FindFirstChild(CONFIG.GUI_NAME) then PlayerGui[CONFIG.GUI_NAME]:Destroy() end speedButtons = {} local gui = Instance.new("ScreenGui") gui.Name = CONFIG.GUI_NAME gui.ResetOnSpawn = false gui.Enabled = true gui.DisplayOrder = 999 gui.Parent = PlayerGui -- Small static visual helpers. local function corner(inst, radius) local c = Instance.new("UICorner") c.CornerRadius = UDim.new(0, radius or 6) c.Parent = inst return c end local function stroke(inst, color, thickness) local s = Instance.new("UIStroke") s.Color = color or Color3.fromRGB(90, 100, 130) s.Thickness = thickness or 1 s.Parent = inst return s end local frame = Instance.new("Frame") frame.Size = UDim2.fromOffset(520, 610) frame.Position = UDim2.new(0.5, -260, 0.5, -305) frame.BackgroundColor3 = Color3.fromRGB(20, 22, 32) frame.BorderSizePixel = 0 corner(frame, 14) stroke(frame, Color3.fromRGB(85, 95, 135), 1.5) frame.Parent = gui local title = Instance.new("TextLabel") title.Size = UDim2.new(1, 0, 0, 36) title.BackgroundColor3 = Color3.fromRGB(32, 36, 58) corner(title, 10) title.Text = "plot copy z made by lwkdontknow" title.TextColor3 = Color3.fromRGB(230, 240, 255) title.TextStrokeColor3 = Color3.new(0, 0, 0) title.TextStrokeTransparency = 0.4 title.TextSize = 15 title.Font = Enum.Font.GothamBold title.TextXAlignment = Enum.TextXAlignment.Left title.Parent = frame local dragging, dragStart, startPos = false, nil, nil title.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then dragging = true dragStart = input.Position startPos = frame.Position input.Changed:Connect(function() if input.UserInputState == Enum.UserInputState.End then dragging = false end end) end end) title.InputChanged:Connect(function(input) if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then local delta = input.Position - dragStart frame.Position = UDim2.new( startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y) end end) local accent = Instance.new("Frame") accent.Size = UDim2.new(1, 0, 0, 3) accent.Position = UDim2.new(0, 0, 0, 36) accent.BorderSizePixel = 0 accent.BackgroundColor3 = Color3.fromRGB(90, 190, 255) accent.Parent = frame local close = Instance.new("TextButton") close.Size = UDim2.fromOffset(30, 26) close.Position = UDim2.new(1, -34, 0, 5) close.BackgroundColor3 = Color3.fromRGB(190, 60, 70) corner(close, 7) stroke(close, Color3.fromRGB(255, 140, 140), 1) close.Text = "X" close.TextColor3 = Color3.new(1, 1, 1) close.TextSize = 14 close.Font = Enum.Font.GothamBold close.Parent = frame close.MouseButton1Click:Connect(function() gui:Destroy() end) -- Always-visible stop button, so a saved-base build can also be cancelled. local stopTop = Instance.new("TextButton") stopTop.Size = UDim2.fromOffset(48, 26) stopTop.Position = UDim2.new(1, -88, 0, 5) stopTop.BackgroundColor3 = Color3.fromRGB(190, 80, 70) stopTop.Text = "STOP" stopTop.TextColor3 = Color3.new(1, 1, 1) stopTop.TextSize = 11 stopTop.Font = Enum.Font.GothamBold corner(stopTop, 7) stroke(stopTop, Color3.fromRGB(255, 150, 140), 1) stopTop.Parent = frame stopTop.MouseButton1Click:Connect(function() safeCall(requestStop) end) statusLabel = Instance.new("TextLabel") statusLabel.Size = UDim2.new(1, -20, 0, 40) statusLabel.Position = UDim2.new(0, 10, 0, 40) statusLabel.BackgroundColor3 = Color3.fromRGB(26, 29, 42) statusLabel.BorderSizePixel = 0 corner(statusLabel, 8) stroke(statusLabel, Color3.fromRGB(70, 80, 110), 1) statusLabel.Text = " Ready - your plot is highlighted green | speed: " .. speedName() statusLabel.TextColor3 = Color3.fromRGB(175, 225, 255) statusLabel.TextSize = 12 statusLabel.Font = Enum.Font.Gotham statusLabel.TextWrapped = true statusLabel.Parent = frame local progressBack = Instance.new("Frame") progressBack.Size = UDim2.new(1, -20, 0, 12) progressBack.Position = UDim2.new(0, 10, 0, 84) progressBack.BackgroundColor3 = Color3.fromRGB(12, 14, 22) progressBack.BorderSizePixel = 0 corner(progressBack, 6) stroke(progressBack, Color3.fromRGB(60, 70, 100), 1) progressBack.Parent = frame progressFill = Instance.new("Frame") progressFill.Size = UDim2.new(0, 0, 1, 0) progressFill.BackgroundColor3 = Color3.fromRGB(70, 190, 130) progressFill.BorderSizePixel = 0 corner(progressFill, 6) progressFill.Parent = progressBack progressLabel = Instance.new("TextLabel") progressLabel.Size = UDim2.new(1, 0, 1, 0) progressLabel.BackgroundTransparency = 1 progressLabel.Text = "Ready" progressLabel.TextColor3 = Color3.new(1, 1, 1) progressLabel.TextSize = 10 progressLabel.Font = Enum.Font.Gotham progressLabel.Parent = progressBack local function sectionLabel(text, y) local l = Instance.new("TextLabel") l.Size = UDim2.new(1, -28, 0, 20) l.Position = UDim2.new(0, 18, 0, y) l.BackgroundTransparency = 1 l.Text = " " .. text l.TextColor3 = Color3.fromRGB(155, 210, 255) l.TextSize = 12 l.Font = Enum.Font.GothamBold l.TextXAlignment = Enum.TextXAlignment.Left l.Parent = frame local bar = Instance.new("Frame") bar.Size = UDim2.new(0, 3, 0, 14) bar.Position = UDim2.new(0, 10, 0, y + 3) bar.BackgroundColor3 = Color3.fromRGB(110, 190, 255) bar.BorderSizePixel = 0 corner(bar, 2) bar.Parent = frame end sectionLabel("--- LIVE PLOTS: click a name to expand ---", 102) local plotList = Instance.new("ScrollingFrame") plotList.Size = UDim2.new(1, -20, 0, 170) plotList.Position = UDim2.new(0, 10, 0, 124) plotList.BackgroundColor3 = Color3.fromRGB(28, 31, 45) plotList.BorderSizePixel = 0 corner(plotList, 8) stroke(plotList, Color3.fromRGB(60, 70, 100), 1) plotList.ScrollBarThickness = 8 plotList.ScrollBarImageColor3 = Color3.fromRGB(110, 160, 220) plotList.CanvasSize = UDim2.new() plotList.Parent = frame local plotLayout = Instance.new("UIListLayout") plotLayout.SortOrder = Enum.SortOrder.LayoutOrder plotLayout.Padding = UDim.new(0, 4) plotLayout.Parent = plotList plotLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function() plotList.CanvasSize = UDim2.new(0, 0, 0, plotLayout.AbsoluteContentSize.Y + 4) end) sectionLabel("--- SAVED BASES: click one to build ---", 302) local savedList = Instance.new("ScrollingFrame") savedList.Size = UDim2.new(1, -20, 0, 120) savedList.Position = UDim2.new(0, 10, 0, 324) savedList.BackgroundColor3 = Color3.fromRGB(28, 31, 45) savedList.BorderSizePixel = 0 corner(savedList, 8) stroke(savedList, Color3.fromRGB(60, 70, 100), 1) savedList.ScrollBarThickness = 8 savedList.ScrollBarImageColor3 = Color3.fromRGB(110, 160, 220) savedList.CanvasSize = UDim2.new() savedList.Parent = frame local savedLayout = Instance.new("UIListLayout") savedLayout.SortOrder = Enum.SortOrder.LayoutOrder savedLayout.Padding = UDim.new(0, 4) savedLayout.Parent = savedList savedLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function() savedList.CanvasSize = UDim2.new(0, 0, 0, savedLayout.AbsoluteContentSize.Y + 4) end) local function mkButton(parent, text, pos, size, color, onClick) local b = Instance.new("TextButton") b.Size = size b.Position = pos b.BackgroundColor3 = color b.Text = text b.TextColor3 = Color3.new(1, 1, 1) b.TextSize = 11 b.Font = Enum.Font.GothamBold corner(b, 6) stroke(b, Color3.new(1, 1, 1), 0.6) b.Parent = parent b.MouseButton1Click:Connect(function() safeCall(onClick) end) return b end -- Build-speed presets. Sits in the small gap above the activity log. local speedCaption = Instance.new("TextLabel") speedCaption.Size = UDim2.new(0, 46, 0, 20) speedCaption.Position = UDim2.new(0, 10, 0, 446) speedCaption.BackgroundTransparency = 1 speedCaption.Text = "Speed:" speedCaption.TextColor3 = Color3.fromRGB(155, 210, 255) speedCaption.TextSize = 10 speedCaption.Font = Enum.Font.GothamBold speedCaption.TextXAlignment = Enum.TextXAlignment.Left speedCaption.Parent = frame local speedX = 58 for _, preset in ipairs(SPEED_PRESETS) do local b = Instance.new("TextButton") b.Size = UDim2.new(0, 82, 0, 20) b.Position = UDim2.new(0, speedX, 0, 446) b.Text = preset.label b.TextColor3 = Color3.new(1, 1, 1) b.TextSize = 9 b.Font = Enum.Font.GothamBold corner(b, 5) stroke(b, Color3.new(1, 1, 1), 0.5) b.Parent = frame b.MouseButton1Click:Connect(function() safeCall(function() setBuildSpeed(preset.lo, preset.hi) end) end) table.insert(speedButtons, { button = b, lo = preset.lo, hi = preset.hi }) speedX += 86 end refreshSpeedButtons() -- Click a plot name to expand/collapse its Save/Build panel. local function plotRow(parent, entry) local container = Instance.new("Frame") container.Size = UDim2.new(1, 0, 0, 44) container.BackgroundColor3 = isMyPlot(entry.plot) and Color3.fromRGB(45, 90, 60) or Color3.fromRGB(44, 48, 68) container.BorderSizePixel = 0 corner(container, 7) stroke(container, Color3.fromRGB(65, 75, 105), 1) container.Parent = parent local sub = entry.parts .. " parts / " .. (entry.objects or entry.parts) .. " objects" local expanded = false local header = Instance.new("TextButton") header.Size = UDim2.new(1, 0, 0, 44) header.BackgroundTransparency = 1 header.Text = " ▸ " .. entry.name .. "\n " .. sub header.TextColor3 = Color3.fromRGB(235, 242, 255) header.TextSize = 12 header.Font = Enum.Font.Gotham header.TextXAlignment = Enum.TextXAlignment.Left header.Parent = container local panel = Instance.new("Frame") panel.Size = UDim2.new(1, 0, 0, 44) panel.Position = UDim2.new(0, 0, 0, 44) panel.BackgroundTransparency = 1 panel.Visible = false panel.Parent = container mkButton(panel, "Save", UDim2.new(0, 10, 0, 5), UDim2.new(0.30, -10, 0, 34), Color3.fromRGB(55, 110, 170), function() savePlot(entry) end) mkButton(panel, "Build", UDim2.new(0.34, 0, 0, 5), UDim2.new(0.30, 0, 0, 34), Color3.fromRGB(60, 150, 90), function() buildLive(entry) end) mkButton(panel, "Stop", UDim2.new(0.68, 0, 0, 5), UDim2.new(0.32, -10, 0, 34), Color3.fromRGB(190, 80, 70), function() requestStop() end) header.MouseButton1Click:Connect(function() expanded = not expanded panel.Visible = expanded container.Size = UDim2.new(1, 0, 0, expanded and 88 or 44) header.Text = (expanded and " ▾ " or " ▸ ") .. entry.name .. "\n " .. sub end) return container end sectionLabel("--- ACTIVITY ---", 470) logLabel = Instance.new("TextLabel") logLabel.Size = UDim2.new(1, -20, 0, 84) logLabel.Position = UDim2.new(0, 10, 0, 488) logLabel.BackgroundColor3 = Color3.fromRGB(18, 20, 30) logLabel.BorderSizePixel = 0 corner(logLabel, 8) stroke(logLabel, Color3.fromRGB(55, 65, 95), 1) logLabel.Text = " " .. table.concat(logLines, "\n") logLabel.TextColor3 = Color3.fromRGB(170, 195, 215) logLabel.TextSize = 10 logLabel.Font = Enum.Font.Gotham logLabel.TextXAlignment = Enum.TextXAlignment.Left logLabel.TextYAlignment = Enum.TextYAlignment.Top logLabel.TextWrapped = true logLabel.Parent = frame mkButton(frame, "Clear plot x2", UDim2.new(0, 10, 1, -34), UDim2.new(0.47, 0, 0, 26), Color3.fromRGB(130, 55, 55), function() if os.time() - pendingClear < 3 then pendingClear = 0 clearMyPlot() else pendingClear = os.time() log("Click Clear again within 3 seconds to confirm") end end) mkButton(frame, "Refresh lists", UDim2.new(0.53, -10, 1, -34), UDim2.new(0.47, 0, 0, 26), Color3.fromRGB(60, 60, 80), function() populate() end) local function row(parent, name, sub, reserve) reserve = reserve or 240 local r = Instance.new("Frame") r.Size = UDim2.new(1, 0, 0, 44) r.BackgroundColor3 = Color3.fromRGB(44, 48, 68) r.BorderSizePixel = 0 corner(r, 7) stroke(r, Color3.fromRGB(65, 75, 105), 1) r.Parent = parent local t = Instance.new("TextLabel") t.Size = UDim2.new(1, -reserve, 1, 0) t.Position = UDim2.new(0, 10, 0, 0) t.BackgroundTransparency = 1 t.Text = name .. "\n" .. sub t.TextColor3 = Color3.fromRGB(235, 242, 255) t.TextSize = 12 t.Font = Enum.Font.Gotham t.TextXAlignment = Enum.TextXAlignment.Left t.Parent = r return r end function populate() for _, child in ipairs(plotList:GetChildren()) do if child:IsA("Frame") then child:Destroy() end end for _, entry in ipairs(listPlots()) do plotRow(plotList, entry) end plotList.CanvasSize = UDim2.new(0, 0, 0, plotLayout.AbsoluteContentSize.Y + 4) for _, child in ipairs(savedList:GetChildren()) do if child:IsA("Frame") then child:Destroy() end end for i, record in ipairs(getSavedBases()) do local r = row(savedList, i .. ". " .. record.name, (record.count or 0) .. " parts", 90) local pick = Instance.new("TextButton") pick.Name = "SavedPick" pick.Size = UDim2.new(1, -90, 1, 0) pick.Position = UDim2.new(0, 0, 0, 0) pick.BackgroundTransparency = 1 pick.Text = "" pick.Parent = r pick.MouseButton1Click:Connect(function() safeCall(function() buildSaved(record) end) end) local deleteAt = 0 local del = mkButton(r, "Del x2", UDim2.new(1, -76, 0, 5), UDim2.fromOffset(72, 34), Color3.fromRGB(150, 60, 60), function() if os.time() - deleteAt < 3 then pcall(delfile, record.path) log("Deleted " .. record.name) populate() else deleteAt = os.time() log("Click Del again within 3 seconds to delete " .. record.name) end end) del.Name = "SavedDelete" end savedList.CanvasSize = UDim2.new(0, 0, 0, savedLayout.AbsoluteContentSize.Y + 4) end populate() return gui end local ok, err = pcall(makeGui) if not ok then showError("UI error: " .. tostring(err)) else log("UI opened") end