Weave0= 1e15 then return tostring(n) end local r = math.floor(n * 1000 + 0.5) / 1000 if r == math.floor(r) then return tostring(math.floor(r)) end return tostring(r) end function B.encode(v, depth, seen) depth = depth or 0 local t = typeof(v) if t == "nil" or t == "boolean" or t == "string" then return v elseif t == "number" then if v ~= v or v == math.huge or v == -math.huge then return tostring(v) end if v ~= math.floor(v) then return tonumber(string.format("%.6g", v)) end return v elseif t == "Instance" then return B.path(v) elseif t == "Vector3" then return string.format("Vector3(%s, %s, %s)", round(v.X), round(v.Y), round(v.Z)) elseif t == "Vector2" then return string.format("Vector2(%s, %s)", round(v.X), round(v.Y)) elseif t == "CFrame" then local rx, ry, rz = v:ToOrientation() return string.format( "CFrame(pos=(%s, %s, %s), rotDeg=(%s, %s, %s))", round(v.X), round(v.Y), round(v.Z), round(math.deg(rx)), round(math.deg(ry)), round(math.deg(rz)) ) elseif t == "Color3" then return string.format( "Color3.fromRGB(%d, %d, %d)", math.floor(v.R * 255 + 0.5), math.floor(v.G * 255 + 0.5), math.floor(v.B * 255 + 0.5) ) elseif t == "UDim2" then return string.format( "UDim2(%s, %s, %s, %s)", round(v.X.Scale), round(v.X.Offset), round(v.Y.Scale), round(v.Y.Offset) ) elseif t == "UDim" then return string.format("UDim(%s, %s)", round(v.Scale), round(v.Offset)) elseif t == "EnumItem" then return tostring(v) elseif t == "BrickColor" then return string.format("BrickColor(%q)", v.Name) elseif t == "NumberRange" then return string.format("NumberRange(%s, %s)", round(v.Min), round(v.Max)) elseif t == "Rect" then return string.format("Rect(%s, %s, %s, %s)", round(v.Min.X), round(v.Min.Y), round(v.Max.X), round(v.Max.Y)) elseif t == "ColorSequence" then local parts = {} for _, k in ipairs(v.Keypoints) do table.insert(parts, round(k.Time) .. ":" .. B.encode(k.Value)) end return "ColorSequence(" .. table.concat(parts, ", ") .. ")" elseif t == "NumberSequence" then local parts = {} for _, k in ipairs(v.Keypoints) do table.insert(parts, round(k.Time) .. ":" .. round(k.Value)) end return "NumberSequence(" .. table.concat(parts, ", ") .. ")" elseif t == "Font" then return string.format("Font(%q, %s, %s)", v.Family, tostring(v.Weight), tostring(v.Style)) elseif t == "table" then if depth > 6 then return "" end seen = seen or {} if seen[v] then return "" end seen[v] = true local out = {} local n = #v local isArray = n > 0 if isArray then for k in pairs(v) do if type(k) ~= "number" or k < 1 or k > n or k % 1 ~= 0 then isArray = false break end end end local count = 0 for k, val in pairs(v) do count += 1 if count > 500 then if isArray then table.insert(out, "… truncated") else out["…"] = "truncated" end break end if isArray and type(k) == "number" then out[k] = B.encode(val, depth + 1, seen) else out[tostring(k)] = B.encode(val, depth + 1, seen) end end seen[v] = nil return out elseif t == "buffer" then return string.format("", buffer.len(v)) end return tostring(v) end function B.getSource(script) local ok, src = pcall(function() return game:GetService("ScriptEditorService"):GetEditorSource(script) end) if ok and type(src) == "string" then return src end return script.Source end function B.setSource(script, source) local done, ok, err, abandoned = false, false, nil, false task.spawn(function() local okEditor, errEditor = pcall(function() game:GetService("ScriptEditorService"):UpdateSourceAsync(script, function(old) if abandoned then return old end return source end) end) ok, err, done = okEditor, errEditor, true end) local started = os.clock() while not done and os.clock() - started < 10 do task.wait(0.05) end if not done then abandoned = true err = "Studio's script editor didn't apply the change within 10 s (is " .. script.Name .. " open in a tab?)" end if not ok then local okDirect, errDirect = pcall(function() script.Source = source end) if not okDirect then error(tostring(errDirect) .. " (editor write failed first: " .. tostring(err) .. ")", 0) end end return true end do local ReflectionService = game:GetService("ReflectionService") local CollectionService = game:GetService("CollectionService") local propCache = {} local function propInfo(className) local cached = propCache[className] if cached then return cached end local map = {} pcall(function() for _, p in ipairs(ReflectionService:GetPropertiesOfClass(className)) do local t = p.Type or {} map[p.Name] = { type = t.EngineType == "ContentId" and "ContentId" or t.ScriptType or t.EngineType, engine = t.EngineType, enum = t.EnumType, readOnly = p.Permits and p.Permits.Write == nil, serialized = p.Serialized ~= false, deprecated = p.Display and p.Display.DeprecationMessage ~= nil, } end end) propCache[className] = map return map end B.propInfo = propInfo local function nums(s) s = string.match(s, "^[%w%.]*%((.*)%)%s*$") or s local out = {} for n in string.gmatch(s, "[-+]?%d*%.?%d+[eE]?[-+]?%d*") do local v = tonumber(n) if v then table.insert(out, v) end end return out end local function arr(v) if type(v) == "table" then if v[1] ~= nil then return v end local x = v.x or v.X if x ~= nil then return { x, v.y or v.Y, v.z or v.Z } end end if type(v) == "number" then return { v } end if type(v) == "string" then return nums(v) end return {} end local function splitTop(s) local parts, depth, buf = {}, 0, {} for i = 1, #s do local ch = string.sub(s, i, i) if ch == "(" or ch == "[" or ch == "{" then depth += 1 elseif ch == ")" or ch == "]" or ch == "}" then depth -= 1 end if ch == "," and depth == 0 then table.insert(parts, (string.gsub(table.concat(buf), "^%s*(.-)%s*$", "%1"))) buf = {} else table.insert(buf, ch) end end local last = string.gsub(table.concat(buf), "^%s*(.-)%s*$", "%1") if last ~= "" then table.insert(parts, last) end return parts end local function inner(s, name) local body = string.match(s, "^%s*" .. name .. "%s*%((.*)%)%s*$") return body end local function expr(s) if not B.hasLoadstring then error("Luau expressions (\"=...\") only work in the edit context", 0) end local fn, err = loadstring("return " .. s, "=value") if not fn then error("bad expression: " .. tostring(err), 0) end return fn() end local function toColor(v) if typeof(v) == "Color3" then return v end if type(v) == "string" then local s = v local hex = string.match(s, "^%s*#?(%x%x%x%x%x%x)%s*$") if hex and (string.sub(s, 1, 1) == "#" or not string.match(s, "^%d+$")) then return Color3.fromHex(hex) end local short = string.match(s, "^%s*#(%x%x%x)%s*$") if short then local r, g, b = string.sub(short, 1, 1), string.sub(short, 2, 2), string.sub(short, 3, 3) return Color3.fromHex(r .. r .. g .. g .. b .. b) end if string.find(s, "fromHSV", 1, true) then local n = nums(s) return Color3.fromHSV(n[1], n[2], n[3]) end if string.find(s, "Color3.new", 1, true) then local n = nums(s) return Color3.new(n[1], n[2], n[3]) end local bc = inner(s, "BrickColor") if bc then return BrickColor.new((string.gsub(bc, "[\"']", ""))).Color end local n = nums(s) if #n >= 3 then return Color3.fromRGB(n[1], n[2], n[3]) end local ok, brick = pcall(BrickColor.new, s) if ok and brick.Name == s then return brick.Color end error("expected a colour like \"#ff8800\", [255,136,0] or \"Color3.fromRGB(255,136,0)\"", 0) end local n = arr(v) if #n >= 3 then if n[1] <= 1 and n[2] <= 1 and n[3] <= 1 then return Color3.new(n[1], n[2], n[3]) end return Color3.fromRGB(n[1], n[2], n[3]) end error("expected a colour like \"#ff8800\" or [255,136,0]", 0) end B.toColor = toColor local function toCFrame(v) if typeof(v) == "CFrame" then return v end if typeof(v) == "Vector3" then return CFrame.new(v) end if type(v) == "table" and v[1] == nil then local pos = v.position or v.Position or v.pos local p = pos and Vector3.new(table.unpack(arr(pos))) or Vector3.zero if v.look_at or v.lookAt then return CFrame.lookAt(p, Vector3.new(table.unpack(arr(v.look_at or v.lookAt)))) end local r = arr(v.rotation or v.Rotation or v.rot or v.orientation or {}) return CFrame.new(p) * CFrame.fromOrientation(math.rad(r[1] or 0), math.rad(r[2] or 0), math.rad(r[3] or 0)) end if type(v) == "string" then local pos = string.match(v, "pos%s*=%s*%(([^%)]*)%)") if pos then local p = nums(pos) local r = nums(string.match(v, "rot%a*%s*=%s*%(([^%)]*)%)") or "0,0,0") return CFrame.new(p[1], p[2], p[3]) * CFrame.fromOrientation(math.rad(r[1] or 0), math.rad(r[2] or 0), math.rad(r[3] or 0)) end end local n = arr(v) if #n == 3 then return CFrame.new(n[1], n[2], n[3]) elseif #n == 6 then return CFrame.new(n[1], n[2], n[3]) * CFrame.fromOrientation(math.rad(n[4]), math.rad(n[5]), math.rad(n[6])) elseif #n == 12 then return CFrame.new(table.unpack(n)) end error("expected a CFrame: [x,y,z], [x,y,z,rx,ry,rz] (degrees) or {position=[..], rotation=[..]} / {position=[..], look_at=[..]}", 0) end local function toSequence(v, isColor) local s = v if type(v) == "number" then return isColor and ColorSequence.new(toColor(v)) or NumberSequence.new(v) end if type(v) == "table" then local keys = {} if type(v[1]) == "table" then for _, k in ipairs(v) do table.insert( keys, isColor and ColorSequenceKeypoint.new(k[1], toColor(k[2])) or NumberSequenceKeypoint.new(k[1], k[2], k[3] or 0) ) end else if isColor and type(v[1]) == "number" and #v == 3 then return ColorSequence.new(toColor(v)) end for i, x in ipairs(v) do local t = #v == 1 and 0 or (i - 1) / (#v - 1) table.insert(keys, isColor and ColorSequenceKeypoint.new(t, toColor(x)) or NumberSequenceKeypoint.new(t, x)) end if #v == 1 then return isColor and ColorSequence.new(toColor(v[1])) or NumberSequence.new(v[1]) end end return isColor and ColorSequence.new(keys) or NumberSequence.new(keys) end s = inner(s, isColor and "ColorSequence" or "NumberSequence") or s if not string.find(s, ":", 1, true) then local parts = splitTop(s) if #parts == 1 then return isColor and ColorSequence.new(toColor(parts[1])) or NumberSequence.new(tonumber(parts[1]) or 0) end local list = {} for _, p in ipairs(parts) do table.insert(list, isColor and p or tonumber(p)) end return toSequence(list, isColor) end local keys = {} for _, part in ipairs(splitTop(s)) do local t, rest = string.match(part, "^%s*([%d%.]+)%s*:%s*(.-)%s*$") if not t then error("bad keypoint \"" .. part .. "\" (use time:value, e.g. \"0:1, 1:0\")", 0) end if isColor then table.insert(keys, ColorSequenceKeypoint.new(tonumber(t), toColor(rest))) else local val, env = string.match(rest, "^([^:]+):?(.*)$") table.insert(keys, NumberSequenceKeypoint.new(tonumber(t), tonumber(val), tonumber(env) or 0)) end end table.sort(keys, function(a, b) return a.Time < b.Time end) return isColor and ColorSequence.new(keys) or NumberSequence.new(keys) end local function toFont(v) if typeof(v) == "Font" then return v end if typeof(v) == "EnumItem" then return Font.fromEnum(v) end local s = tostring(v) local body = inner(s, "Font") if body then local parts = splitTop(body) local family = string.gsub(parts[1] or "", "[\"']", "") local weight = parts[2] and Enum.FontWeight[string.match(parts[2], "(%w+)%s*$")] or Enum.FontWeight.Regular local style = parts[3] and Enum.FontStyle[string.match(parts[3], "(%w+)%s*$")] or Enum.FontStyle.Normal if string.find(family, "://", 1, true) then return Font.new(family, weight, style) end return Font.fromName(family, weight, style) end if string.find(s, "://", 1, true) then return Font.new((string.gsub(s, "^%s*(.-)%s*$", "%1"))) end local family, weightName = string.match(s, "^%s*([%w]+)[%s:]+(%a+)%s*$") local okWeight, weightItem = pcall(function() return family and Enum.FontWeight[weightName] end) if okWeight and weightItem then return Font.fromName(family, weightItem) end local okEnum, enumFont = pcall(function() return Enum.Font[s] end) if okEnum and enumFont then return Font.fromEnum(enumFont) end return Font.fromName(s) end local function toEnum(v, enumType) if typeof(v) == "EnumItem" then return v end local enum = Enum[enumType] if type(v) == "number" then for _, item in ipairs(enum:GetEnumItems()) do if item.Value == v then return item end end end local name = string.match(tostring(v), "([%w_]+)%s*$") local ok, item = pcall(function() return enum[name] end) if ok and item then return item end local names = {} for _, it in ipairs(enum:GetEnumItems()) do if string.lower(it.Name) == string.lower(name or "") then return it end if #names < 40 then table.insert(names, it.Name) end end error(string.format("%q is not an Enum.%s (valid: %s)", tostring(v), enumType, table.concat(names, ", ")), 0) end local function toContent(v, isContent) local s = type(v) == "number" and string.format("%.0f", v) or tostring(v) if type(v) == "number" or string.match(s, "^%d+$") then s = "rbxassetid://" .. s end if isContent then return Content.fromUri(s) end return s end function B.decode(v, typeName, enumType, relativeTo) if type(v) == "string" and string.sub(v, 1, 1) == "=" and typeName ~= "string" then return expr(string.sub(v, 2)) end if typeName == "nil" or typeName == nil then return v end if v == "nil" and (typeName == "Instance" or typeName == "Object") then return nil end local t = typeName if t == "bool" or t == "boolean" then if type(v) == "string" then return string.lower(v) == "true" end return not not v elseif t == "number" or t == "float" or t == "double" or t == "int" or t == "int64" or t == "int32" then local n = tonumber(v) if n == nil then error("expected a number", 0) end return n elseif t == "string" then return tostring(v) elseif t == "ContentId" or t == "Content" then return toContent(v, t == "Content" and typeof(Content) ~= "nil") elseif t == "Vector3" then if typeof(v) == "Vector3" then return v end local n = arr(v) if #n == 1 then return Vector3.new(n[1], n[1], n[1]) end if #n < 3 then error("expected a Vector3 like [4,1,2] or \"4,1,2\"", 0) end return Vector3.new(n[1], n[2], n[3]) elseif t == "Vector2" then local n = arr(v) if #n < 2 then error("expected a Vector2 like [10,20]", 0) end return Vector2.new(n[1], n[2]) elseif t == "Vector3int16" then local n = arr(v) return Vector3int16.new(n[1], n[2], n[3]) elseif t == "Vector2int16" then local n = arr(v) return Vector2int16.new(n[1], n[2]) elseif t == "CFrame" then return toCFrame(v) elseif t == "Color3" then return toColor(v) elseif t == "BrickColor" then if type(v) == "string" and not string.find(v, "%(") then return BrickColor.new(v) end return BrickColor.new(toColor(v)) elseif t == "UDim2" then if typeof(v) == "UDim2" then return v end local s = type(v) == "string" and v or "" local n = arr(v) if string.find(s, "fromScale", 1, true) or (type(v) == "table" and (v.scale or v.Scale)) then local sc = type(v) == "table" and arr(v.scale or v.Scale) or n return UDim2.fromScale(sc[1], sc[2]) elseif string.find(s, "fromOffset", 1, true) or (type(v) == "table" and (v.offset or v.Offset)) then local of = type(v) == "table" and arr(v.offset or v.Offset) or n return UDim2.fromOffset(of[1], of[2]) end if #n ~= 4 then error("expected a UDim2: [xScale, xOffset, yScale, yOffset], \"fromScale(0.5,0.5)\" or \"fromOffset(200,50)\"", 0) end return UDim2.new(n[1], n[2], n[3], n[4]) elseif t == "UDim" then local n = arr(v) return UDim.new(n[1] or 0, n[2] or 0) elseif t == "Rect" then local n = arr(v) return Rect.new(n[1], n[2], n[3], n[4]) elseif t == "NumberRange" then local n = arr(v) return NumberRange.new(n[1], n[2] or n[1]) elseif t == "NumberSequence" then return toSequence(v, false) elseif t == "ColorSequence" then return toSequence(v, true) elseif t == "Font" then return toFont(v) elseif t == "EnumItem" or t == "Enum" or t == "token" then if not enumType then error("unknown enum type", 0) end return toEnum(v, enumType) elseif t == "PhysicalProperties" then if v == "default" or v == false then return nil end local n = arr(v) return PhysicalProperties.new(n[1], n[2] or 0.3, n[3] or 0.5, n[4] or 1, n[5] or 1) elseif t == "Instance" or t == "Object" then if typeof(v) == "Instance" then return v end local s = tostring(v) if relativeTo then local rel = B.resolveFrom(relativeTo, s) if rel then return rel end end return B.resolve(s) end return v end function B.resolveFrom(root, path) local cur = root for _, seg in ipairs(B.splitPath(path)) do cur = cur and cur:FindFirstChild(seg) end if cur == root then return nil end return cur end local function editDistance(a, b) if math.abs(#a - #b) > 2 then return 99 end local prev = {} for j = 0, #b do prev[j] = j end for i = 1, #a do local cur = { [0] = i } for j = 1, #b do local cost = string.byte(a, i) == string.byte(b, j) and 0 or 1 cur[j] = math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost) end prev = cur end return prev[#b] end function B.suggestProp(className, prop) local want = string.lower(prop) local hits = {} for name, info in pairs(propInfo(className)) do local low = string.lower(name) if not info.deprecated and string.match(name, "^%u") and (string.find(low, want, 1, true) or string.find(want, low, 1, true) or editDistance(low, want) <= 2) then table.insert(hits, name) end end table.sort(hits, function(a, b) return #a < #b end) if #hits == 0 then return "" end return " (did you mean " .. table.concat(hits, ", ", 1, math.min(#hits, 4)) .. "?)" end local PSEUDO = { Pivot = function(inst, v) inst:PivotTo(toCFrame(v)) end, Scale = function(inst, v) if inst:IsA("Model") then inst:ScaleTo(tonumber(v)) else error("Scale only works on Models", 0) end end, } local function typeOf(inst, prop) local info = propInfo(inst.ClassName)[prop] if info then return info.type, info.enum, info end local ok, cur = pcall(function() return inst[prop] end) if not ok then return nil end if typeof(cur) == "EnumItem" then return "EnumItem", tostring(cur.EnumType) end return typeof(cur) end function B.setProp(inst, prop, value, relativeTo) if PSEUDO[prop] and not propInfo(inst.ClassName)[prop] then PSEUDO[prop](inst, value) return end if prop == "Position" and inst:IsA("Model") then inst:PivotTo(CFrame.new(B.decode(value, "Vector3"))) return end if prop == "Source" and inst:IsA("LuaSourceContainer") then local fn, err = true, nil if B.hasLoadstring then fn, err = loadstring(tostring(value), "=" .. inst.Name) end if not fn then error("syntax error: " .. tostring(err), 0) end B.setSource(inst, tostring(value)) return end local typeName, enumType, info = typeOf(inst, prop) if typeName == nil then local ok = pcall(function() return inst[prop] end) if not ok then error(string.format("%s has no property %q%s", inst.ClassName, prop, B.suggestProp(inst.ClassName, prop)), 0) end end if info and info.readOnly then error(prop .. " is read-only", 0) end local decoded = B.decode(value, typeName, enumType, relativeTo) inst[prop] = decoded end local function hasValue(t) return type(t) == "table" and next(t) ~= nil end function B.setAttrs(inst, attrs) for k, v in pairs(attrs) do if type(v) == "string" then if string.sub(v, 1, 1) == "=" and B.hasLoadstring and loadstring("return " .. string.sub(v, 2)) then v = expr(string.sub(v, 2)) elseif string.match(v, "^Vector3%(") then v = B.decode(v, "Vector3") elseif string.match(v, "^Vector2%(") then v = B.decode(v, "Vector2") elseif string.match(v, "^Color3") or string.match(v, "^#%x%x%x%x%x%x$") then v = toColor(v) elseif string.match(v, "^UDim2%(") then v = B.decode(v, "UDim2") elseif string.match(v, "^CFrame%(") then v = toCFrame(v) elseif string.match(v, "^NumberRange%(") then v = B.decode(v, "NumberRange") elseif string.match(v, "^NumberSequence%(") then v = toSequence(v, false) elseif string.match(v, "^ColorSequence%(") then v = toSequence(v, true) end end if v == "nil" then v = nil end inst:SetAttribute(k, v) end end local RESERVED = { class = true, className = true, ClassName = true, name = true, Name = true, properties = true, props = true, attributes = true, tags = true, children = true, parent = true, Parent = true, source = true, path = true, } local FIRST = { Shape = 1, MeshId = 2, TextureID = 3, Size = 4, CFrame = 5, Position = 6, Orientation = 7 } local function sortedKeys(t) local keys = {} for k in pairs(t) do table.insert(keys, k) end table.sort(keys, function(a, b) local fa, fb = FIRST[a] or 100, FIRST[b] or 100 if fa ~= fb then return fa < fb end return a < b end) return keys end local function specProps(spec) local props = {} for k, v in pairs(spec) do if not RESERVED[k] then props[k] = v end end for k, v in pairs(spec.properties or spec.props or {}) do props[k] = v end return props end function B.build(spec, parent, errors) errors = errors or {} local created = {} local deferred = {} local function make(s, depth) local class = s.class or s.className or s.ClassName if type(class) ~= "string" then table.insert(errors, "a node has no class (use {class = \"Part\", ...})") return nil end local ok, inst = pcall(Instance.new, class) if not ok then table.insert(errors, string.format("%q is not a creatable class", class)) return nil end inst.Name = s.name or s.Name or class table.insert(created, inst) local props = specProps(s) if s.source ~= nil then props.Source = s.source end for _, k in ipairs(sortedKeys(props)) do local tName = typeOf(inst, k) if tName == "Instance" or tName == "Object" then table.insert(deferred, { inst = inst, prop = k, value = props[k] }) else local okSet, err = pcall(B.setProp, inst, k, props[k]) if not okSet then table.insert(errors, string.format("%s.%s: %s", inst.Name, k, tostring(err))) end end end if hasValue(s.attributes) then local okA, err = pcall(B.setAttrs, inst, s.attributes) if not okA then table.insert(errors, inst.Name .. " attributes: " .. tostring(err)) end end for _, tag in ipairs(s.tags or {}) do local okT, err = pcall(inst.AddTag, inst, tag) if not okT then table.insert(errors, inst.Name .. " tag: " .. tostring(err)) end end for _, child in ipairs(s.children or {}) do local c = make(child, depth + 1) if c then c.Parent = inst end end return inst end local root = make(spec, 0) if root then for _, d in ipairs(deferred) do local okSet, err = pcall(function() local target local cur = d.inst while cur and not target do target = B.resolveFrom(cur, tostring(d.value)) if cur == root then break end cur = cur.Parent end if not target and d.value ~= "nil" then target = B.resolve(tostring(d.value)) end d.inst[d.prop] = target end) if not okSet then table.insert(errors, string.format("%s.%s: %s", d.inst.Name, d.prop, tostring(err))) end end root.Parent = parent end return root, errors, #created end function B.select(opts) local list = {} local needle = opts.name_contains and string.lower(opts.name_contains) local function matches(d) return (not opts.class_name or d:IsA(opts.class_name)) and (not opts.name or d.Name == opts.name) and (not needle or string.find(string.lower(d.Name), needle, 1, true) ~= nil) and (not opts.tag or d:HasTag(opts.tag)) end if (opts.paths and #opts.paths > 0) or opts.selection then local pool = {} if opts.paths and #opts.paths > 0 then for _, p in ipairs(opts.paths) do table.insert(pool, B.resolve(p)) end else pool = B.selection() end for _, d in ipairs(pool) do if matches(d) then table.insert(list, d) end end return list, false end local root = B.resolve(opts.under or "Workspace") local limit = opts.limit or 5000 local pool = opts.tag and CollectionService:GetTagged(opts.tag) or root:GetDescendants() local breathe = B.slicer() for _, d in ipairs(pool) do breathe() if (not opts.tag or d:IsDescendantOf(root) or d == root) and matches(d) then if #list >= limit then return list, true end table.insert(list, d) end end return list, false end local defaults = {} local NOISE = { Parent = true, Name = true, ClassName = true, SourceAssetId = true, UniqueId = true, HistoryId = true, Capabilities = true, Sandboxed = true, DefinesCapabilities = true, ScriptGuid = true, Source = true, Position = true, Orientation = true, Rotation = true, BrickColor = true, } B.NOISE = NOISE function B.nonDefault(inst) local class = inst.ClassName local def = defaults[class] if def == nil then local ok, fresh = pcall(Instance.new, class) def = ok and fresh or false defaults[class] = def end local out = {} for name, info in pairs(propInfo(class)) do if not info.deprecated and not info.readOnly and info.type ~= "nil" and string.match(name, "^%u") and not NOISE[name] then local ok, v = pcall(function() return inst[name] end) if ok and typeof(v) ~= "RBXScriptSignal" then local same = false if def then local okD, dv = pcall(function() return def[name] end) same = okD and (dv == v or B.encode(dv) == B.encode(v)) end if not same then out[name] = B.encode(v) end end end end return out, def ~= false end function B.markWaypoint(inst) inst:SetAttribute("__RodexMark", true) inst:SetAttribute("__RodexMark", nil) end function B.childSummary(inst) local counts, order = {}, {} local kids = inst:GetChildren() for _, c in ipairs(kids) do if not counts[c.ClassName] then counts[c.ClassName] = 0 table.insert(order, c.ClassName) end counts[c.ClassName] += 1 end table.sort(order, function(a, b) return counts[a] > counts[b] end) local bits = {} for i, cls in ipairs(order) do if i > 5 then table.insert(bits, "…") break end table.insert(bits, counts[cls] .. " " .. cls) end return #kids, table.concat(bits, ", ") end B.UI_SCREENS = { { name = "phone", w = 844, h = 390 }, { name = "small phone", w = 667, h = 375 }, { name = "tablet", w = 1024, h = 768 }, } local function udim(u, len) return u.Scale * len + u.Offset end local function fitConstraints(holder, w, h) local sc = holder:FindFirstChildOfClass("UISizeConstraint") if sc then w = math.clamp(w, sc.MinSize.X, math.max(sc.MinSize.X, sc.MaxSize.X)) h = math.clamp(h, sc.MinSize.Y, math.max(sc.MinSize.Y, sc.MaxSize.Y)) end local ar = holder:FindFirstChildOfClass("UIAspectRatioConstraint") if ar and ar.AspectRatio > 0 then local r = ar.AspectRatio if ar.AspectType == Enum.AspectType.ScaleWithParentSize then if ar.DominantAxis == Enum.DominantAxis.Height then w = h * r else h = w / r end elseif w / math.max(h, 1e-6) > r then w = h * r else h = w / r end end return w, h end local function layOut(gui, sw, sh, inset) local full = gui.IgnoreGuiInset or gui.ScreenInsets == Enum.ScreenInsets.None or gui.ScreenInsets == Enum.ScreenInsets.DeviceSafeInsets local top = full and 0 or inset local boxes, order = {}, {} boxes[gui] = { x = 0, y = top, w = sw, h = sh - top, root = true } local function visit(p, pb) local cx, cy, cw, ch = pb.x, pb.y, pb.w, pb.h local pad = p:FindFirstChildOfClass("UIPadding") if pad then local l, r = udim(pad.PaddingLeft, pb.w), udim(pad.PaddingRight, pb.w) local t, b = udim(pad.PaddingTop, pb.h), udim(pad.PaddingBottom, pb.h) cx, cy, cw, ch = cx + l, cy + t, math.max(0, cw - l - r), math.max(0, ch - t - b) end local grid = p:FindFirstChildOfClass("UIGridLayout") local list = not grid and p:FindFirstChildOfClass("UIListLayout") local cellW, cellH if grid then cellW, cellH = fitConstraints(grid, udim(grid.CellSize.X, cw), udim(grid.CellSize.Y, ch)) end local vertical = (list and list.FillDirection == Enum.FillDirection.Vertical) or (grid and grid.FillDirection == Enum.FillDirection.Vertical) or false local shown, autoAlong = {}, false for _, c in ipairs(p:GetChildren()) do if c:IsA("GuiObject") then local w, h if grid then w, h = cellW, cellH else w, h = fitConstraints(c, udim(c.Size.X, cw), udim(c.Size.Y, ch)) end local managed = (list or grid) ~= nil local x = managed and cx or cx + udim(c.Position.X, cw) - c.AnchorPoint.X * w local y = managed and cy or cy + udim(c.Position.Y, ch) - c.AnchorPoint.Y * h local a = c.AutomaticSize local box = { x = x, y = y, w = w, h = h, managed = managed, autoX = a == Enum.AutomaticSize.X or a == Enum.AutomaticSize.XY, autoY = a == Enum.AutomaticSize.Y or a == Enum.AutomaticSize.XY, } if pb.dynamic or c:FindFirstChildOfClass("UIScale") then box.dynamic = true end boxes[c] = box table.insert(order, c) if c.Visible then table.insert(shown, box) if (vertical and box.autoY) or (not vertical and box.autoX) then autoAlong = true end end visit(c, box) end end if (list or grid) and #shown > 0 and not autoAlong and not p:IsA("ScrollingFrame") then if list then if not list.Wraps then local room = vertical and ch or cw local need = udim(list.Padding, room) * (#shown - 1) for _, b in ipairs(shown) do need += vertical and b.h or b.w end pb.need, pb.room, pb.items = need, room, #shown end else local across, cross = vertical and ch or cw, vertical and cw or ch local cellA, cellB = vertical and cellH or cellW, vertical and cellW or cellH local gapA = udim(vertical and grid.CellPadding.Y or grid.CellPadding.X, across) local gapB = udim(vertical and grid.CellPadding.X or grid.CellPadding.Y, cross) local perLine = math.max(1, math.floor((across + gapA) / math.max(cellA + gapA, 1))) local lines = math.ceil(#shown / perLine) pb.need, pb.room, pb.items = lines * cellB + (lines - 1) * gapB, cross, #shown pb.crossVertical = not vertical end pb.vertical = vertical end end if gui:FindFirstChildOfClass("UIScale") then return boxes, order end visit(gui, boxes[gui]) return boxes, order end local function sticksOut(b, p) return math.max(p.x - b.x, p.y - b.y, (b.x + b.w) - (p.x + p.w), (b.y + b.h) - (p.y + p.h), 0) end local function overlaps(b, p) return b.x < p.x + p.w and b.x + b.w > p.x and b.y < p.y + p.h and b.y + b.h > p.y end local function shaped(d, gui) if (d:IsA("ImageLabel") or d:IsA("ImageButton")) and d.Image ~= "" and d.ImageTransparency < 1 and d.ScaleType == Enum.ScaleType.Stretch then return true end if d.BackgroundTransparency >= 0.95 and not d:FindFirstChildOfClass("UIStroke") then return false end return d:IsA("GuiButton") or d:FindFirstChildOfClass("UICorner") ~= nil or d.Parent == gui end function B.uiFit(roots, opts) opts = opts or {} local inset = opts.inset or 58 local cam = workspace.CurrentCamera local vp = cam and cam.ViewportSize or Vector2.new(1280, 720) local base = { w = math.max(vp.X, 1280), h = math.max(vp.Y, 720) } local out, seen, guis, known, scope = {}, {}, {}, {}, {} local max = opts.max or 300 local function add(code, d, detail) seen[code] = seen[code] or {} if seen[code][d] or #out >= max then return end seen[code][d] = true table.insert(out, { code = code, inst = d, detail = detail }) end for _, r in ipairs(roots) do local gui = r:IsA("ScreenGui") and r or r:FindFirstAncestorWhichIsA("ScreenGui") if gui then if not known[gui] then known[gui] = true table.insert(guis, gui) end scope[r] = true end end local function inScope(d) local cur = d while cur do if scope[cur] then return true end cur = cur.Parent end return false end local function px(v) return math.floor(v + 0.5) end for _, gui in ipairs(guis) do local mb, order = layOut(gui, base.w, base.h, inset) for _, screen in ipairs(opts.screens or B.UI_SCREENS) do local m = layOut(gui, screen.w, screen.h, inset) local on = string.format("on a %s (%dx%d)", screen.name, screen.w, screen.h) local stretched = {} for _, d in ipairs(order) do local b, bb = m[d], mb[d] local p = d.Parent local pbox, pbase = m[p], mb[p] if b and bb and not b.dynamic and inScope(d) then if p ~= gui and pbox and not b.managed and not b.autoX and not b.autoY and not pbox.autoX and not pbox.autoY and not p:IsA("ScrollingFrame") and overlaps(b, pbox) then local over = sticksOut(b, pbox) if over > math.max(4, 0.03 * math.min(pbox.w, pbox.h)) and sticksOut(bb, pbase) <= 1 then add("ui_overflow", d, string.format("%s it sticks out of %s by %d px%s", on, p.Name, px(over), p.ClipsDescendants and " and gets cut off" or "")) end end if p == gui and not b.autoX and not b.autoY then local scr = { x = 0, y = 0, w = screen.w, h = screen.h } local over = sticksOut(b, scr) if over > 4 and overlaps(b, scr) and sticksOut(bb, { x = 0, y = 0, w = base.w, h = base.h }) <= 1 then add("ui_offscreen_small", d, string.format("%s it runs %d px past the screen edge (%dx%d px there)", on, px(over), px(b.w), px(b.h))) end end if b.need and bb.need and b.need - b.room > 4 and bb.need - bb.room <= 1 then local growAxis = (b.crossVertical == nil and b.vertical) or b.crossVertical if not (growAxis and b.autoY) and not (not growAxis and b.autoX) then add("ui_list_overflow", d, string.format("%s its %d items need %d px but it has %d px", on, b.items, px(b.need), px(b.room))) end end if shaped(d, gui) and b.w > 8 and b.h > 8 and bb.w > 8 and bb.h > 8 then local rb, rs = bb.w / bb.h, b.w / b.h local change = math.max(rs / rb, rb / rs) local inside = false local cur = p while cur and cur ~= gui do if stretched[cur] then inside = true break end cur = cur.Parent end if change > 1.25 and (d:IsA("ImageLabel") or d:IsA("ImageButton") or (rb > 0.5 and rb < 2.2)) and not inside then stretched[d] = true add("ui_stretched", d, string.format("%.2f:1 at desktop size, %.2f:1 %s", rb, rs, on)) end end if (d:IsA("TextLabel") or d:IsA("TextButton") or d:IsA("TextBox")) and not d.TextScaled and d.Text ~= "" and not b.autoY then local tb = d.TextBounds local function needH(w) if not d.TextWrapped or tb.X <= 0 or tb.Y <= 0 then return d.TextSize end local lines = math.max(1, math.floor(tb.Y / math.max(d.TextSize, 1) + 0.5)) return math.ceil(lines * tb.X / math.max(w - 2, 1)) * (tb.Y / lines) end local tooNarrow = not d.TextWrapped and not b.autoX and tb.X > 0 and b.w < tb.X - 2 and bb.w >= tb.X - 2 if (b.h < needH(b.w) - 2 and bb.h >= needH(bb.w) - 2) or tooNarrow then add("ui_text_squeezed", d, string.format("%s TextSize %d in a %dx%d px box", on, d.TextSize, px(b.w), px(b.h))) end end end end end end return out end local UI_FIT_FIX = { ui_overflow = "sticks out of its frame on smaller screens (size and place children with Scale, or give the frame a UIAspectRatioConstraint so they keep their room)", ui_offscreen_small = "runs off a phone screen (Scale size and position with AnchorPoint, and a UISizeConstraint MaxSize instead of a fixed pixel size)", ui_list_overflow = "runs out of room for its items on smaller screens (a ScrollingFrame with AutomaticCanvasSize, Scale row heights, or AutomaticSize)", ui_stretched = "changes shape with the screen (add a UIAspectRatioConstraint with its desktop ratio)", ui_text_squeezed = "has text bigger than its box on smaller screens (TextScaled with a UITextSizeConstraint, or AutomaticSize Y)", } function B.reviewBuild(roots) local notes = {} local falling, falls, tiny, wide, scaled, prices, links, rate, shadows, mute = 0, nil, {}, {}, 0, {}, {}, 0, 0, 0 for _, root in ipairs(roots) do local list = root:GetDescendants() table.insert(list, 1, root) local gui = root:IsA("LayerCollector") and root or root:FindFirstAncestorWhichIsA("LayerCollector") local scaledGui = (gui and gui:FindFirstChildWhichIsA("UIScale", true)) ~= nil for _, d in ipairs(list) do if d:IsA("BasePart") then local okA, rootPart = pcall(function() return d.AssemblyRootPart end) local anchored = d.Anchored or (okA and rootPart and rootPart.Anchored) local model = d:FindFirstAncestorWhichIsA("Model") local character = model and model:FindFirstChildWhichIsA("Humanoid") ~= nil if not anchored and not character then falling += 1 falls = falls or B.path(d) end elseif d:IsA("GuiObject") then local s = d.Size local offsetOnly = s.X.Scale == 0 and s.Y.Scale == 0 if d:IsA("GuiButton") and offsetOnly and s.X.Offset > 0 and (s.X.Offset < 36 or s.Y.Offset < 36) and #tiny < 3 then table.insert(tiny, d.Name .. " " .. s.X.Offset .. "x" .. s.Y.Offset) end if not scaledGui and ((s.X.Scale == 0 and s.X.Offset > 760) or (s.Y.Scale == 0 and s.Y.Offset > 360)) and #wide < 3 then table.insert(wide, d.Name .. " " .. s.X.Offset .. "x" .. s.Y.Offset) end if d:IsA("TextLabel") or d:IsA("TextButton") or d:IsA("TextBox") then if d.TextScaled and not d:FindFirstChildWhichIsA("UITextSizeConstraint") then scaled += 1 end local t = string.lower(d.Text) if (string.find(t, "r%$%s*%d") or string.find(t, "%d%s*robux")) and #prices < 2 then table.insert(prices, d.Name) end if (string.find(t, "discord", 1, true) or string.find(t, ".gg/", 1, true) or string.find(t, "youtube", 1, true) or string.find(t, "tiktok", 1, true)) and #links < 2 then table.insert(links, d.Name) end end elseif d:IsA("ParticleEmitter") then if d.Enabled then rate += d.Rate end elseif d:IsA("Light") then if d.Shadows then shadows += 1 end elseif d:IsA("Sound") then if d.SoundId == "" then mute += 1 end end end end if falling > 0 then table.insert(notes, falling .. " unanchored part" .. (falling == 1 and "" or "s") .. " not attached to anything anchored (e.g. " .. falls .. ") will fall when the game runs: anchor them unless they should move") end if #tiny > 0 then table.insert(notes, "buttons smaller than ~40px are hard to tap on phones: " .. table.concat(tiny, ", ")) end if #wide > 0 then table.insert(notes, "fixed-size UI bigger than a phone screen (no UIScale): " .. table.concat(wide, ", ") .. "; use Scale sizes or a UIScale") end if scaled > 2 then table.insert(notes, scaled .. " TextScaled labels without a UITextSizeConstraint: their text sizes won't match and can get unreadable on phones") end if #prices > 0 then table.insert(notes, "Robux prices typed into text (" .. table.concat(prices, ", ") .. ") go stale under regional pricing: set them from MarketplaceService:GetProductInfoAsync") end if #links > 0 then table.insert(notes, "off-platform links in UI text (" .. table.concat(links, ", ") .. ") break the Community Standards: use the game page's Social Links") end if rate > 400 then table.insert(notes, "particle Rate adds up to " .. math.floor(rate) .. "/s: heavy for phones; lower Rate or Lifetime") end if shadows > 4 then table.insert(notes, shadows .. " lights cast shadows: costly on phones; keep shadows on the few that matter") end if mute > 0 then table.insert(notes, mute .. " Sound" .. (mute == 1 and " has" or "s have") .. " no SoundId: find one with sfx_find (or search_assets, asset_type Audio)") end local fit = B.uiFit(roots, { max = 80 }) local byCode, codes = {}, {} for _, f in ipairs(fit) do local list = byCode[f.code] if not list then list = { n = 0 } byCode[f.code] = list table.insert(codes, f.code) end list.n += 1 if #list < 3 then table.insert(list, f.inst.Name .. " (" .. f.detail .. ")") end end for _, code in ipairs(codes) do local list = byCode[code] local more = list.n > #list and (" and " .. (list.n - #list) .. " more") or "" table.insert(notes, "UI that doesn't scale, " .. UI_FIT_FIX[code] .. ": " .. table.concat(list, "; ") .. more) end return notes end end do local W = { on = false, roots = {}, known = {}, sent = {}, expect = {}, dirty = {}, scriptConns = {}, rootConns = {}, seq = 0, gen = 0, } B.weave = W local live = {} local function hold(c) live[c] = true return c end local function drop(c) live[c] = nil c:Disconnect() end track({ Disconnect = function() W.on = false W.gen += 1 if W.tree then W.tree.on = false end for c in pairs(live) do pcall(function() c:Disconnect() end) end table.clear(live) end, }) local budget = os.clock() local function breathe(gen, of) if os.clock() - budget > 0.01 then task.wait() budget = os.clock() end return (of or W).gen == gen end local okSES, SES = pcall(game.GetService, game, "ScriptEditorService") if not okSES then SES = nil end local function isScript(inst) return inst:IsA("Script") or inst:IsA("LocalScript") or inst:IsA("ModuleScript") end local function clsOf(inst) if inst:IsA("LocalScript") then return "LocalScript" elseif inst:IsA("ModuleScript") then return "ModuleScript" end return "Script" end local function norm(s) return (string.gsub(s, "\r\n", "\n")) end local function fnv(s) local h = 0x811c9dc5 for i = 1, #s do h = bit32.bxor(h, string.byte(s, i)) h = (bit32.lshift(h, 24) + h * 403) % 4294967296 end return string.format("%08x", h) end W.fnv = fnv local function pathOf(inst) local segs = {} local cur = inst while cur and cur.Parent ~= game do if cur.Parent == nil then return nil end table.insert(segs, 1, cur.Name) cur = cur.Parent end if not cur then return nil end local root = cur.ClassName if not W.roots[root] then return nil end table.insert(segs, 1, root) return segs end local function dupAlong(inst, cache) local cur = inst while cur and cur.Parent and cur.Parent ~= game do local parent = cur.Parent local counts = cache and cache[parent] if not counts then counts = {} for _, sib in ipairs(parent:GetChildren()) do counts[sib.Name] = (counts[sib.Name] or 0) + 1 end if cache then cache[parent] = counts end end if (counts[cur.Name] or 0) > 1 then return true end cur = parent end return false end local function keyOf(segs) local parts = {} for i, s in ipairs(segs) do parts[i] = (string.gsub(string.gsub(s, "%%", "%%25"), "/", "%%2F")) end return table.concat(parts, "/") end local function sourceOf(inst) return norm(B.getSource(inst)) end local outbox = {} local sending = false local function pump() if sending then return end sending = true while #outbox > 0 do local data = outbox[1] local ok, res = B.event(data) if ok and not (type(res) == "table" and res.Success == false) then table.remove(outbox, 1) else data.tries = (data.tries or 0) + 1 if data.tries >= 5 then table.remove(outbox, 1) else task.wait(0.5 * data.tries) end end end sending = false end local function emit(kind, data) data.type = "weave" data.kind = kind W.seq += 1 data.seq = W.seq table.insert(outbox, data) if #outbox > 500 then table.remove(outbox, 1) end task.spawn(pump) end local function flush(inst) W.dirty[inst] = nil if not W.on or not inst.Parent then return end local segs = pathOf(inst) if not segs then return end local text = sourceOf(inst) local exp = W.expect[inst] if exp ~= nil then W.expect[inst] = nil if exp == text then W.sent[inst] = text return end end if W.sent[inst] == text then return end W.sent[inst] = text emit("text", { key = keyOf(segs), cls = clsOf(inst), text = text, dup = dupAlong(inst) or nil }) end local function touch(inst) if W.dirty[inst] then return end W.dirty[inst] = true task.delay(W.debounce or 0.08, flush, inst) end local function watchScript(inst) if W.scriptConns[inst] then return end local list = {} table.insert( list, hold(inst:GetPropertyChangedSignal("Source"):Connect(function() touch(inst) end)) ) local function moved() task.defer(function() if not W.on then return end local old = W.known[inst] local segs = inst.Parent and pathOf(inst) local key = segs and keyOf(segs) if key == old then return end W.known[inst] = key if old and key then emit("move", { from = old, to = key, cls = clsOf(inst), text = sourceOf(inst), dup = dupAlong(inst) or nil }) elseif old then emit("remove", { key = old }) elseif key then W.sent[inst] = sourceOf(inst) emit("add", { key = key, cls = clsOf(inst), text = W.sent[inst], dup = dupAlong(inst) or nil }) end end) end table.insert(list, hold(inst:GetPropertyChangedSignal("Name"):Connect(moved))) table.insert(list, hold(inst.AncestryChanged:Connect(moved))) W.scriptConns[inst] = list W.known[inst] = (function() local segs = pathOf(inst) return segs and keyOf(segs) end)() end local function unwatchScript(inst) local list = W.scriptConns[inst] if list then for _, c in ipairs(list) do drop(c) end end W.scriptConns[inst] = nil end local function sweep() for inst, old in pairs(W.known) do local segs = inst.Parent and pathOf(inst) local key = segs and keyOf(segs) if key ~= old then W.known[inst] = key if old and key then emit("move", { from = old, to = key, cls = clsOf(inst), text = sourceOf(inst), dup = dupAlong(inst) or nil }) elseif old then emit("remove", { key = old }) end end end end function W.stop() W.on = false W.gen += 1 for _, c in ipairs(W.rootConns) do drop(c) end W.rootConns = {} for inst in pairs(W.scriptConns) do unwatchScript(inst) end for _, c in pairs(W.docConns or {}) do drop(c) end W.docConns = {} W.known, W.sent, W.expect, W.dirty = {}, {}, {}, {} return true end function W.start(cfg) W.stop() local gen = W.gen W.on = true W.roots = {} W.debounce = cfg.debounce or 0.08 for _, name in ipairs(cfg.roots or {}) do W.roots[name] = true end local svcs = {} for name in pairs(W.roots) do local ok, svc = pcall(function() return game:FindService(name) or game:GetService(name) end) if ok and svc then table.insert(svcs, svc) table.insert( W.rootConns, hold(svc.DescendantAdded:Connect(function(d) if not W.on or not isScript(d) then return end watchScript(d) task.defer(function() local segs = d.Parent and pathOf(d) if not segs then return end W.known[d] = keyOf(segs) W.sent[d] = sourceOf(d) emit("add", { key = W.known[d], cls = clsOf(d), text = W.sent[d], dup = dupAlong(d) or nil }) end) end)) ) table.insert( W.rootConns, hold(svc.DescendantRemoving:Connect(function(d) if not W.on or not isScript(d) then return end local old = W.known[d] task.defer(function() if d.Parent and d:IsDescendantOf(game) then return end unwatchScript(d) W.known[d] = nil if old then emit("remove", { key = old }) end end) end)) ) end end W.docConns = {} local function watchDoc(doc) if W.docConns[doc] then return end local okCmd, isCmd = pcall(function() return doc:IsCommandBar() end) if okCmd and isCmd then return end local pending, last = false, nil local okSel, selConn = pcall(function() return doc.SelectionChanged:Connect(function(pl, pc, al, ac) last = { pl, pc, al, ac } if pending then return end pending = true task.delay(0.15, function() pending = false if not W.on or not last then return end local okS, inst = pcall(function() return doc:GetScript() end) local key = okS and inst and W.known[inst] if key and W.activeKey ~= key then W.activeKey = key if W.onPresence and W.people then pcall(W.onPresence, W.people) end end if key then emit("cursor", { key = key, line = last[1], ch = last[2], anchorLine = last[3], anchorCh = last[4], typing = W.dirty[inst] ~= nil or nil }) end end) end) end) if okSel and selConn then W.docConns[doc] = hold(selConn) end end pcall(function() for _, doc in ipairs(SES:GetScriptDocuments()) do watchDoc(doc) end end) pcall(function() table.insert(W.rootConns, hold(SES.TextDocumentDidOpen:Connect(watchDoc))) table.insert( W.rootConns, hold(SES.TextDocumentDidClose:Connect(function(doc) local c = W.docConns[doc] if c then drop(c) W.docConns[doc] = nil end end)) ) end) local okDoc, conn = pcall(function() return hold(SES.TextDocumentDidChange:Connect(function(doc) if not W.on then return end local ok, inst = pcall(function() return doc:GetScript() end) if ok and inst and W.scriptConns[inst] then touch(inst) end end)) end) if okDoc and conn then table.insert(W.rootConns, conn) end local list = {} local cache = {} for _, svc in ipairs(svcs) do local all = svc:GetDescendants() for i, d in ipairs(all) do if i % 200 == 0 and not breathe(gen) then error("Weave restarted while reading the place", 0) end if isScript(d) and d.Parent then watchScript(d) local segs = pathOf(d) if segs then local src = sourceOf(d) W.sent[d] = src table.insert(list, { key = keyOf(segs), cls = clsOf(d), hash = fnv(src), len = #src, dup = dupAlong(d, cache) or nil }) if not breathe(gen) then error("Weave restarted while reading the place", 0) end end end end end task.spawn(function() while alive and W.on and W.gen == gen do task.wait(1) if alive and W.on and W.gen == gen then pcall(sweep) end end end) return { scripts = list, editorEvents = okDoc and conn ~= nil } end local function find(segs) local ok, cur = pcall(function() return game:FindService(segs[1]) or game:GetService(segs[1]) end) if not ok or not cur then return nil end for i = 2, #segs do local hit for _, c in ipairs(cur:GetChildren()) do if c.Name == segs[i] then if hit then return nil, "ambiguous" end hit = c end end if not hit then return nil end cur = hit end return cur end local function ensureParent(segs) local ok, cur = pcall(function() return game:FindService(segs[1]) or game:GetService(segs[1]) end) if not ok or not cur then return nil end for i = 2, #segs - 1 do local nextInst = cur:FindFirstChild(segs[i]) if not nextInst then nextInst = Instance.new("Folder") nextInst.Name = segs[i] nextInst.Parent = cur end cur = nextInst end return cur end local function splitLines(s) local out = {} local start = 1 while true do local i = string.find(s, "\n", start, true) if not i then table.insert(out, string.sub(s, start)) break end table.insert(out, string.sub(s, start, i - 1)) start = i + 1 end return out end local function colEnd(line) local n = utf8.len(line) return (n or #line) + 1 end local function editOpen(inst, cur, want, hunks) local doc = SES and SES:FindScriptDocument(inst) if not doc or not hunks then return false end local lines = splitLines(cur) local n = #lines for i = #hunks, 1, -1 do local h = hunks[i] local s, e, L = h.s, h.e, h.lines or {} local ok if e <= n then local text = #L > 0 and (table.concat(L, "\n") .. "\n") or "" ok = pcall(function() doc:EditTextAsync(text, s, 1, e, 1) end) elseif s > 1 then local text = #L > 0 and ("\n" .. table.concat(L, "\n")) or "" ok = pcall(function() doc:EditTextAsync(text, s - 1, colEnd(lines[s - 1]), n, colEnd(lines[n])) end) else ok = pcall(function() doc:EditTextAsync(table.concat(L, "\n"), 1, 1, n, colEnd(lines[n])) end) end if not ok then return false end end local okText, now = pcall(function() return norm(doc:GetText()) end) return okText and now == want end function W.apply(list) local results = {} for i, item in ipairs(list or {}) do local res = { key = item.key } results[i] = res local ok, err = pcall(function() local inst, why = find(item.segs) if why == "ambiguous" then res.error = "two instances share this path" return end if item.delete then if inst and isScript(inst) then W.known[inst] = nil unwatchScript(inst) inst:Destroy() end res.ok = true return end if item.from then local old = find(item.from) if old and isScript(old) and not inst then local parent = ensureParent(item.segs) if not parent then res.error = "no place for it" return end W.known[old] = keyOf(item.segs) old.Name = item.segs[#item.segs] old.Parent = parent inst = old end end if inst and not isScript(inst) then res.error = "something that isn't a script already has this path" return end if inst and clsOf(inst) ~= item.cls then local parent = inst.Parent local fresh = Instance.new(item.cls) fresh.Name = inst.Name for _, c in ipairs(inst:GetChildren()) do c.Parent = fresh end W.expect[fresh] = item.text B.setSource(fresh, item.text) W.known[inst] = nil unwatchScript(inst) inst:Destroy() fresh.Parent = parent watchScript(fresh) W.known[fresh] = item.key W.sent[fresh] = item.text res.ok = true res.hash = fnv(item.text) return end if not inst then local parent = ensureParent(item.segs) if not parent then res.error = "no place for it" return end local s = Instance.new(item.cls) s.Name = item.segs[#item.segs] W.expect[s] = item.text B.setSource(s, item.text) W.sent[s] = item.text s.Parent = parent watchScript(s) W.known[s] = item.key res.ok = true res.hash = fnv(item.text) return end local cur = sourceOf(inst) if item.base and fnv(cur) ~= item.base and cur ~= item.text then res.stale = true res.text = cur W.sent[inst] = cur return end if cur == item.text then W.sent[inst] = cur res.ok = true res.hash = fnv(cur) return end W.expect[inst] = item.text if not editOpen(inst, cur, item.text, item.hunks) then B.setSource(inst, item.text) end W.sent[inst] = item.text res.ok = true res.hash = fnv(sourceOf(inst)) end) if not ok then res.error = tostring(err) end end return results end function W.presence(p) W.people = p if W.onPresence then pcall(W.onPresence, p) end return true end function W.read(keys) local out = {} for i, segs in ipairs(keys or {}) do local inst = find(segs) if inst and isScript(inst) then local src = sourceOf(inst) W.sent[inst] = src out[i] = { cls = clsOf(inst), text = src } else out[i] = false end end return out end local T = { on = false, roots = {}, ids = {}, byId = {}, conns = {}, rootConns = {}, queue = {}, flushing = false, expect = {} } W.tree = T local HttpService = game:GetService("HttpService") local SKIP_CLASS = { Terrain = true, Camera = true, Player = true } local function skipped(inst) if SKIP_CLASS[inst.ClassName] or isScript(inst) or not inst.Archivable then return true end local cur = inst.Parent while cur and cur ~= game do if isScript(cur) then return true end cur = cur.Parent end return false end local function rootOf(inst) local cur = inst while cur and cur.Parent ~= game do cur = cur.Parent end return cur and T.roots[cur.ClassName] and cur or nil end local function idOf(inst, make) local id = T.ids[inst] if id then return id end local okA, a = pcall(function() return inst:GetAttribute("WeaveId") end) if okA and type(a) == "string" and #a > 8 and not T.byId[a] then id = a elseif make then if make == "path" then local parts = {} local cur = inst while cur and cur.Parent and cur.Parent ~= game do local n = 0 for _, sib in ipairs(cur.Parent:GetChildren()) do if sib == cur then break end if sib.Name == cur.Name and sib.ClassName == cur.ClassName then n += 1 end end table.insert(parts, 1, cur.Name .. "\1" .. cur.ClassName .. "\1" .. n) cur = cur.Parent end local s = (cur and cur.ClassName or "") .. "\2" .. table.concat(parts, "\2") id = "p" .. fnv(s) .. fnv(s .. "#weave") if T.byId[id] then id = string.gsub(HttpService:GenerateGUID(false), "-", "") end else id = string.gsub(HttpService:GenerateGUID(false), "-", "") end T.expect[inst] = T.expect[inst] or {} T.expect[inst]["@WeaveId"] = id pcall(function() inst:SetAttribute("WeaveId", id) end) else return nil end T.ids[inst] = id T.byId[id] = inst return id end local function parentRef(inst) local p = inst.Parent if not p then return nil end if p.Parent == game then return "root:" .. p.ClassName end return idOf(p, true) end local function propsOf(inst) local out = {} local nd = B.nonDefault(inst) local info = B.propInfo(inst.ClassName) for k, v in pairs(nd) do local i = info[k] if not (i and (i.type == "Instance" or i.engine == "Instance")) then out[k] = v end end return out end local function attrsOf(inst) local out = {} for k, v in pairs(inst:GetAttributes()) do if k ~= "WeaveId" and string.sub(k, 1, 2) ~= "__" then out[k] = { t = typeof(v), v = B.encode(v) } end end return out end local function fullOp(inst) return { op = "set", id = idOf(inst, true), c = inst.ClassName, n = inst.Name, p = parentRef(inst), props = propsOf(inst), attrs = attrsOf(inst) } end local function queue(id, patch) local q = T.queue[id] if not q then q = { op = "set", id = id } T.queue[id] = q end for k, v in pairs(patch) do if k == "props" or k == "attrs" then q[k] = q[k] or {} for pk, pv in pairs(v) do q[k][pk] = pv end else q[k] = v end end if not T.flushing then T.flushing = true task.delay(0.1, function() T.flushing = false if not T.on then return end local ops = {} for _, op in pairs(T.queue) do table.insert(ops, op) end T.queue = {} if #ops > 0 then emit("tree", { ops = ops }) end end) end end local function expected(inst, key, value) local e = T.expect[inst] if e and e[key] ~= nil then local want = e[key] e[key] = nil return want == value end return false end local function watchInst(inst) if T.conns[inst] then return end local id = idOf(inst, true) local list = {} table.insert( list, hold(inst.Changed:Connect(function(prop) if not T.on or prop == "Parent" then return end if prop == "Name" then if not expected(inst, "Name", inst.Name) then queue(id, { n = inst.Name }) end return end if B.NOISE and B.NOISE[prop] then return end local info = B.propInfo(inst.ClassName)[prop] if not info or info.readOnly or info.type == "Instance" or info.engine == "Instance" then return end local ok, v = pcall(function() return inst[prop] end) if not ok then return end local enc = B.encode(v) if expected(inst, prop, HttpService:JSONEncode({ enc })) then return end queue(id, { props = { [prop] = enc } }) end)) ) table.insert( list, hold(inst.AttributeChanged:Connect(function(name) if not T.on or name == "WeaveId" or string.sub(name, 1, 2) == "__" then return end local v = inst:GetAttribute(name) local enc = v == nil and { t = "nil" } or { t = typeof(v), v = B.encode(v) } if expected(inst, "@" .. name, HttpService:JSONEncode(enc)) then return end queue(id, { attrs = { [name] = enc } }) end)) ) table.insert( list, hold(inst.AncestryChanged:Connect(function() task.defer(function() if not T.on then return end if not inst.Parent or not rootOf(inst) or skipped(inst) then return end local p = parentRef(inst) if expected(inst, "Parent", p) then return end queue(id, { p = p }) end) end)) ) T.conns[inst] = list end local function unwatchInst(inst) local list = T.conns[inst] if list then for _, c in ipairs(list) do drop(c) end end T.conns[inst] = nil end function W.treeStop() T.on = false T.gen = (T.gen or 0) + 1 for _, c in ipairs(T.rootConns) do drop(c) end T.rootConns = {} for inst in pairs(T.conns) do unwatchInst(inst) end T.ids, T.byId, T.queue, T.expect = {}, {}, {}, {} return true end function W.treeStart(cfg) W.treeStop() local gen = T.gen T.on = true T.roots = {} for _, name in ipairs(cfg.roots or {}) do T.roots[name] = true end local nodes = {} local tooBig = {} local max = tonumber(cfg.max) or 5000 for name in pairs(T.roots) do local ok, svc = pcall(function() return game:FindService(name) or game:GetService(name) end) local all = ok and svc and svc:GetDescendants() or {} if #all > max then T.roots[name] = nil table.insert(tooBig, { root = name, count = #all }) ok = false end if ok and svc then for i, d in ipairs(all) do if i % 100 == 0 and not breathe(gen, T) then error("Weave restarted while reading the place", 0) end if d.Parent and not skipped(d) then idOf(d, "path") watchInst(d) table.insert(nodes, fullOp(d)) end end table.insert( T.rootConns, hold(svc.DescendantAdded:Connect(function(d) if not T.on then return end task.defer(function() if not d.Parent or skipped(d) or T.conns[d] then return end watchInst(d) local id = idOf(d, true) if T.expect[d] and T.expect[d]["@created"] then T.expect[d]["@created"] = nil return end queue(id, fullOp(d)) end) end)) ) table.insert( T.rootConns, hold(svc.DescendantRemoving:Connect(function(d) if not T.on or not T.conns[d] then return end local id = T.ids[d] task.defer(function() if d.Parent and d:IsDescendantOf(game) and rootOf(d) then return end unwatchInst(d) if id and T.byId[id] == d then T.byId[id] = nil T.ids[d] = nil if T.expect[d] and T.expect[d]["@gone"] then return end T.queue[id] = nil emit("tree", { ops = { { op = "del", id = id } } }) end end) end)) ) end end return { nodes = nodes, tooBig = tooBig } end local function decodeAttr(a) if type(a) ~= "table" or a.t == "nil" then return nil end return B.decode(a.v, a.t) end function W.treeApply(ops) local results = {} local pendingParent = {} for i, op in ipairs(ops or {}) do local ok, err = pcall(function() local inst = T.byId[op.id] if op.op == "del" then if inst then T.expect[inst] = T.expect[inst] or {} T.expect[inst]["@gone"] = true unwatchInst(inst) T.byId[op.id] = nil T.ids[inst] = nil inst:Destroy() end return end if not inst and op.adopt and op.p then local parent = string.sub(op.p, 1, 5) == "root:" and game:FindService(string.sub(op.p, 6)) or T.byId[op.p] if parent then for _, c in ipairs(parent:GetChildren()) do if c.Name == op.n and c.ClassName == op.c and not T.ids[c] and c:GetAttribute("WeaveId") == nil then inst = c T.ids[c] = op.id T.byId[op.id] = c T.expect[c] = T.expect[c] or {} T.expect[c]["@WeaveId"] = op.id c:SetAttribute("WeaveId", op.id) watchInst(c) break end end end end local created = false if not inst then if not op.c then return end inst = Instance.new(op.c) created = true T.ids[inst] = op.id T.byId[op.id] = inst T.expect[inst] = { ["@created"] = true, ["@WeaveId"] = op.id } inst:SetAttribute("WeaveId", op.id) end local e = T.expect[inst] or {} T.expect[inst] = e if op.n and inst.Name ~= op.n then e.Name = op.n inst.Name = op.n end for k, v in pairs(op.props or {}) do local okP = pcall(B.setProp, inst, k, v) if okP then local okR, now = pcall(function() return inst[k] end) if okR then e[k] = HttpService:JSONEncode({ B.encode(now) }) end end end for k, a in pairs(op.attrs or {}) do local v = decodeAttr(a) e["@" .. k] = HttpService:JSONEncode(v == nil and { t = "nil" } or { t = typeof(v), v = B.encode(v) }) pcall(function() inst:SetAttribute(k, v) end) end if op.p then table.insert(pendingParent, { inst = inst, p = op.p, created = created }) end end) results[i] = ok or tostring(err) end for _, pp in ipairs(pendingParent) do local parent = string.sub(pp.p, 1, 5) == "root:" and game:FindService(string.sub(pp.p, 6)) or T.byId[pp.p] if parent and pp.inst.Parent ~= parent then local e = T.expect[pp.inst] or {} T.expect[pp.inst] = e e.Parent = pp.p pcall(function() pp.inst.Parent = parent end) if pp.created then watchInst(pp.inst) end end end return results end end local W = B.weave local PROTOCOL = 1 local DEFAULT_PORT = 34873 local COUNTED = { "Workspace", "ReplicatedFirst", "ReplicatedStorage", "ServerScriptService", "ServerStorage", "StarterGui", "StarterPack", "StarterPlayer", "Lighting", "SoundService", "Teams", "Chat", "TextChatService", } local Link = { state = "off", gen = 0, client = HttpService:GenerateGUID(false), port = tonumber(plugin:GetSetting("Weave_Port")) or DEFAULT_PORT, auto = plugin:GetSetting("Weave_AutoConnect") ~= false, connectedAt = 0, need = nil, message = nil, info = nil, } function Link.request(method, path, body) local encoded = nil if body ~= nil then local okEncode, text = pcall(function() return HttpService:JSONEncode(body) end) if not okEncode then return nil, nil, tostring(text) end encoded = text end local ok, res = pcall(function() return HttpService:RequestAsync({ Url = "http://127.0.0.1:" .. tostring(Link.port) .. path, Method = method, Headers = { ["Content-Type"] = "application/json", ["X-Weave"] = tostring(PROTOCOL) }, Body = encoded, }) end) if not ok then return nil, nil, tostring(res) end local decoded = nil pcall(function() decoded = HttpService:JSONDecode(res.Body) end) return res, decoded, nil end function B.event(payload) local res, _, err = Link.request("POST", "/weave/events", { k = Link.client, events = { payload } }) if not res then return false, err end return true, res end local onChange = function() end local onPanel = function(_) end local function setState(state, message) Link.state = state Link.message = message task.spawn(onChange) end local METHODS = { start = function(a) return W.start(a) end, read = function(a) return W.read(a) end, apply = function(a) return W.apply(a) end, stop = function() return W.stop() end, presence = function(a) return W.presence(a) end, treeStart = function(a) return W.treeStart(a) end, treeApply = function(a) return W.treeApply(a) end, treeStop = function() return W.treeStop() end, isOn = function() return W.on == true end, panel = function(a) onPanel(a) return true end, } local function runJob(job, gen) local fn = METHODS[job.method] local reply = { id = job.id, ok = false, error = "Unknown job" } if fn then local ok, value = pcall(fn, job.args) reply = ok and { id = job.id, ok = true, value = value } or { id = job.id, ok = false, error = tostring(value) } end if Link.gen ~= gen then return end local res, _, err = Link.request("POST", "/weave/result", { k = Link.client, results = { reply } }) if not res and err and reply.ok then Link.request("POST", "/weave/result", { k = Link.client, results = { { id = job.id, ok = false, error = err } } }) end end local function stopWatching() pcall(W.stop) pcall(W.treeStop) end local connect local function lost(gen, message) if Link.gen ~= gen then return end Link.gen += 1 stopWatching() setState("off", message) if Link.auto then local mine = Link.gen task.delay(3, function() if Link.gen == mine and Link.auto and Link.state == "off" then connect({ quiet = true }) end end) end end local function pollLoop(gen) local fails = 0 while Link.gen == gen do local res, body = Link.request("GET", "/weave/poll?k=" .. Link.client) if Link.gen ~= gen then return end if res and res.StatusCode == 200 and body then fails = 0 for _, job in ipairs(body.jobs or {}) do task.spawn(runJob, job, gen) end elseif res and res.StatusCode == 410 then lost(gen, "Weave restarted. Connecting again.") return else fails += 1 if fails >= 3 then lost(gen, "Lost the connection to Weave.") return end task.wait(1) end end end local function countScripts() local n = 0 local seen = 0 for _, name in ipairs(COUNTED) do local svc = game:FindService(name) if svc then for _, d in ipairs(svc:GetDescendants()) do seen += 1 if d:IsA("LuaSourceContainer") then n += 1 end if seen % 20000 == 0 then task.wait() end end end end return n end connect = function(opts) opts = opts or {} if Link.state == "connecting" or Link.state == "on" then return end Link.gen += 1 local gen = Link.gen if not opts.quiet then setState("connecting") end local res, body, err = Link.request("POST", "/weave/hello", { k = Link.client, protocol = PROTOCOL, placeId = game.PlaceId, gameId = game.GameId, placeName = game.Name, scripts = countScripts(), first = opts.first, relink = opts.relink, }) if Link.gen ~= gen then return end if not res then local text = tostring(err) local refused = string.find(text, "ConnectFail", 1, true) or string.find(text, "refused", 1, true) or string.find(text, "Connect", 1, true) local blocked = string.find(text, "permission", 1, true) or string.find(text, "not enabled", 1, true) local message = refused and "Weave isn't running yet. Start it in your code editor." or blocked and "Studio blocked the connection. Allow Weave to reach localhost when Studio asks." or text setState("off", not opts.quiet and message or nil) if Link.auto then task.delay(3, function() if Link.gen == gen and Link.auto and Link.state == "off" then connect({ quiet = true }) end end) end return end if type(body) ~= "table" then setState("off", "Something else answered on port " .. tostring(Link.port) .. ".") return end if body.ok then Link.need = nil Link.info = body Link.connectedAt = os.clock() if not Link.auto then Link.auto = true plugin:SetSetting("Weave_AutoConnect", true) end setState("on") task.spawn(pollLoop, gen) return end if body.need then Link.need = body setState("need") return end setState("off", tostring(body.error or "Weave refused the connection.")) end Link.connect = function(opts) task.spawn(connect, opts) end function Link.cancelNeed() Link.need = nil Link.auto = false plugin:SetSetting("Weave_AutoConnect", false) setState("off") end function Link.reconnect() Link.gen += 1 stopWatching() Link.state = "off" Link.connect() end function Link.disconnect() if os.clock() - Link.connectedAt < 1.5 then return end Link.gen += 1 Link.auto = false plugin:SetSetting("Weave_AutoConnect", false) stopWatching() local client = Link.client task.spawn(function() Link.request("POST", "/weave/bye", { k = client }) end) setState("off") end function Link.setPort(port) Link.port = port plugin:SetSetting("Weave_Port", port) end function Link.setAuto(on) Link.auto = on plugin:SetSetting("Weave_AutoConnect", on) if on and Link.state == "off" then Link.connect({ quiet = true }) end end function Link.command(cmd, args) local res, body, err = Link.request("POST", "/weave/command", { k = Link.client, cmd = cmd, args = args or {} }) if not res then return { ok = false, error = err } end return type(body) == "table" and body or { ok = false, error = "No answer" } end do local Studio = settings().Studio local TweenService = game:GetService("TweenService") local DOWNLOAD = "rodexai.dev/weave" local ICON = "" local PALETTES = { Dark = { bg = "1b1b1b", card = "242424", edge = "333333", raised = "333333", hover = "3f3f3f", track = "2e2e2e", thumb = "4a4a4a", text = "f2f2f2", muted = "a8a8a8", faint = "7a7a7a", fill = "ffffff", fillHover = "e3e3e3", ink = "0d0d0d", ok = "6fcf8f", warn = "e0b25a", bad = "ef6b62", accent = "5c9dff", orange = "f0a35e", }, Light = { bg = "f6f6f6", card = "ffffff", edge = "e6e6e6", raised = "ececec", hover = "e2e2e2", track = "e9e9e9", thumb = "ffffff", text = "0d0d0d", muted = "5d5d5d", faint = "8f8f8f", fill = "0d0d0d", fillHover = "2e2e2e", ink = "ffffff", ok = "23864a", warn = "a66f0c", bad = "c23b33", accent = "2563eb", orange = "c2701d", }, } local SOURCE_COLOR = { Studio = "accent", folder = "ok", editor = "orange", teammate = "warn", restore = "faint" } local function themeName() local ok, name = pcall(function() return Studio.Theme.Name end) return ok and name == "Light" and "Light" or "Dark" end local P = PALETTES[themeName()] local themed = {} local function paint(inst, prop, key) themed[inst] = themed[inst] or {} themed[inst][prop] = key inst[prop] = Color3.fromHex(P[key]) return inst end local function new(class, props, parent) local inst = Instance.new(class) for k, v in pairs(props or {}) do inst[k] = v end if class == "Frame" or class == "ScrollingFrame" then inst.BorderSizePixel = 0 end inst.Parent = parent return inst end local function round(inst, r) new("UICorner", { CornerRadius = r == "full" and UDim.new(1, 0) or UDim.new(0, r) }, inst) return inst end local function pad(inst, x, y) new("UIPadding", { PaddingLeft = UDim.new(0, x), PaddingRight = UDim.new(0, x), PaddingTop = UDim.new(0, y or x), PaddingBottom = UDim.new(0, y or x), }, inst) return inst end local function edge(inst) local s = new("UIStroke", { Thickness = 1, ApplyStrokeMode = Enum.ApplyStrokeMode.Border }, inst) paint(s, "Color", "edge") return inst end local order = 0 local function nextOrder() order += 1 return order end local function column(parent, gap) local f = new("Frame", { Size = UDim2.fromScale(1, 0), AutomaticSize = Enum.AutomaticSize.Y, BackgroundTransparency = 1, LayoutOrder = nextOrder(), }, parent) new("UIListLayout", { Padding = UDim.new(0, gap or 8), SortOrder = Enum.SortOrder.LayoutOrder }, f) return f end local function row(parent, gap, height) local f = new("Frame", { Size = UDim2.new(1, 0, 0, height or 32), BackgroundTransparency = 1, LayoutOrder = nextOrder(), }, parent) new("UIListLayout", { Padding = UDim.new(0, gap or 8), FillDirection = Enum.FillDirection.Horizontal, VerticalAlignment = Enum.VerticalAlignment.Center, SortOrder = Enum.SortOrder.LayoutOrder, }, f) return f end local function text(parent, value, size, key, opts) opts = opts or {} local l = new("TextLabel", { Size = opts.size or UDim2.fromScale(1, 0), AutomaticSize = opts.size and Enum.AutomaticSize.None or Enum.AutomaticSize.Y, BackgroundTransparency = 1, Text = value or "", TextSize = size, Font = opts.bold and Enum.Font.BuilderSansBold or opts.medium and Enum.Font.BuilderSansMedium or Enum.Font.BuilderSans, TextWrapped = opts.wrap ~= false, TextTruncate = opts.wrap == false and Enum.TextTruncate.AtEnd or Enum.TextTruncate.None, TextXAlignment = opts.align or Enum.TextXAlignment.Left, TextYAlignment = Enum.TextYAlignment.Center, LayoutOrder = nextOrder(), }, parent) paint(l, "TextColor3", key or "text") return l end local function card(parent, gap) local f = new("Frame", { Size = UDim2.fromScale(1, 0), AutomaticSize = Enum.AutomaticSize.Y, LayoutOrder = nextOrder(), }, parent) paint(f, "BackgroundColor3", "card") round(f, 14) edge(f) pad(f, 12, 12) new("UIListLayout", { Padding = UDim.new(0, gap or 8), SortOrder = Enum.SortOrder.LayoutOrder }, f) return f end local EASE = TweenInfo.new(0.16, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) local function button(parent, label, kind, onClick, width) local primary = kind == "primary" local b = new("TextButton", { Size = width and UDim2.new(width, width == 1 and 0 or -4, 0, 32) or UDim2.new(0, 0, 0, 32), AutomaticSize = width and Enum.AutomaticSize.None or Enum.AutomaticSize.X, AutoButtonColor = false, Text = label, TextSize = 13, Font = Enum.Font.BuilderSansMedium, LayoutOrder = nextOrder(), }, parent) round(b, "full") if not width then pad(b, 14, 0) end paint(b, "BackgroundColor3", primary and "fill" or "raised") paint(b, "TextColor3", primary and "ink" or "text") b.MouseEnter:Connect(function() TweenService:Create(b, EASE, { BackgroundColor3 = Color3.fromHex(P[primary and "fillHover" or "hover"]) }):Play() end) b.MouseLeave:Connect(function() TweenService:Create(b, EASE, { BackgroundColor3 = Color3.fromHex(P[primary and "fill" or "raised"]) }):Play() end) b.MouseButton1Click:Connect(function() task.spawn(onClick) end) return b end local function inputBox(parent, placeholder, mono) local box = new("TextBox", { Size = UDim2.new(1, 0, 0, 32), PlaceholderText = placeholder or "", Text = "", TextSize = 12, Font = mono and Enum.Font.RobotoMono or Enum.Font.BuilderSans, ClearTextOnFocus = false, TextXAlignment = Enum.TextXAlignment.Left, TextTruncate = Enum.TextTruncate.AtEnd, LayoutOrder = nextOrder(), }, parent) round(box, 10) edge(box) paint(box, "BackgroundColor3", "bg") paint(box, "TextColor3", "text") paint(box, "PlaceholderColor3", "faint") pad(box, 10, 0) return box end local function copyBox(parent, value) local box = inputBox(parent, "", true) box.Text = value box.TextEditable = false box.Focused:Connect(function() box.SelectionStart = 1 box.CursorPosition = #box.Text + 1 end) return box end local function switchRow(parent, label, sub, get, set) local holder = column(parent, 2) local r = row(holder, 8, 24) text(r, label, 13, "text", { size = UDim2.new(1, -46, 1, 0), wrap = false }) local track = new("TextButton", { Size = UDim2.fromOffset(36, 20), Text = "", AutoButtonColor = false, LayoutOrder = nextOrder() }, r) round(track, "full") local knob = new("Frame", { Size = UDim2.fromOffset(16, 16), AnchorPoint = Vector2.new(0, 0.5), Position = UDim2.new(0, 2, 0.5, 0) }, track) round(knob, "full") knob.BackgroundColor3 = Color3.new(1, 1, 1) if sub then text(holder, sub, 11.5, "faint") end local last = nil local function refresh() local on = get() if on == last then return end last = on paint(track, "BackgroundColor3", on and "accent" or "thumb") TweenService:Create(knob, EASE, { Position = on and UDim2.new(1, -18, 0.5, 0) or UDim2.new(0, 2, 0.5, 0) }):Play() end track.MouseButton1Click:Connect(function() set(not get()) refresh() end) refresh() return refresh end local function segmented(parent, choices, get, set) local track = new("Frame", { Size = UDim2.new(1, 0, 0, 30), LayoutOrder = nextOrder() }, parent) round(track, "full") paint(track, "BackgroundColor3", "track") local width = 1 / #choices local thumb = new("Frame", { Size = UDim2.new(width, -4, 1, -4), Position = UDim2.new(0, 2, 0, 2) }, track) round(thumb, "full") paint(thumb, "BackgroundColor3", "thumb") local labels = {} local last = {} local function refresh() local current = get() if last[1] == current then return end last[1] = current for i, c in ipairs(choices) do local on = c[1] == current paint(labels[i], "TextColor3", on and "text" or "muted") if on then TweenService:Create(thumb, EASE, { Position = UDim2.new((i - 1) * width, 2, 0, 2) }):Play() end end end for i, c in ipairs(choices) do local b = new("TextButton", { Size = UDim2.fromScale(width, 1), Position = UDim2.fromScale((i - 1) * width, 0), BackgroundTransparency = 1, Text = c[2], TextSize = 12.5, Font = Enum.Font.BuilderSansMedium, ZIndex = 2, }, track) labels[i] = b b.MouseButton1Click:Connect(function() set(c[1]) refresh() end) end refresh() return refresh end local braids = {} local function braid(parent, w, h, count, size) local holder = new("Frame", { Size = UDim2.fromOffset(w, h), BackgroundTransparency = 1, LayoutOrder = nextOrder() }, parent) local dots = {} for strand = 1, 2 do for i = 1, count do local d = new("Frame", { Size = UDim2.fromOffset(size, size), AnchorPoint = Vector2.new(0.5, 0.5) }, holder) round(d, "full") paint(d, "BackgroundColor3", strand == 1 and "text" or "accent") table.insert(dots, { d = d, strand = strand, i = i, front = nil }) end end local function set(phase) for _, o in ipairs(dots) do local t = (o.i - 1) / (count - 1) local a = t * math.pi * 3 + phase + (o.strand == 2 and math.pi or 0) o.d.Position = UDim2.fromOffset(t * (w - size) + size / 2, h / 2 + math.sin(a) * (h / 2 - size / 2)) local front = math.cos(a) > 0 if front ~= o.front then o.front = front o.d.ZIndex = front and 3 or 2 o.d.BackgroundTransparency = front and 0 or 0.55 end end end set(0.6) table.insert(braids, { set = set, holder = holder }) return holder end local toolbar = plugin:CreateToolbar("Weave") local toggle = toolbar:CreateButton("weave_panel", "Live sync with your folder, editor and team", ICON, "Weave") toggle.ClickableWhenViewportHidden = true local info = DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, false, true, 320, 380, 240, 160) local okWidget, widget = pcall(function() return plugin:CreateDockWidgetPluginGuiAsync("WeavePanelV3", info) end) if not okWidget then widget = plugin:CreateDockWidgetPluginGui("WeavePanelV3", info) end widget.Title = "Weave" widget.Name = "WeavePanel" widget.ZIndexBehavior = Enum.ZIndexBehavior.Sibling toggle:SetActive(widget.Enabled) toggle.Click:Connect(function() widget.Enabled = not widget.Enabled end) widget:GetPropertyChangedSignal("Enabled"):Connect(function() toggle:SetActive(widget.Enabled) end) local root = new("ScrollingFrame", { Size = UDim2.fromScale(1, 1), ScrollBarThickness = 4, AutomaticCanvasSize = Enum.AutomaticSize.Y, CanvasSize = UDim2.new(), ScrollingDirection = Enum.ScrollingDirection.Y, }, widget) paint(root, "BackgroundColor3", "bg") paint(root, "ScrollBarImageColor3", "faint") pad(root, 12, 12) new("UIListLayout", { Padding = UDim.new(0, 10), SortOrder = Enum.SortOrder.LayoutOrder }, root) local head = new("Frame", { Size = UDim2.new(1, 0, 0, 26), BackgroundTransparency = 1, LayoutOrder = nextOrder() }, root) local headLeft = new("Frame", { Size = UDim2.fromScale(0.62, 1), BackgroundTransparency = 1 }, head) new("UIListLayout", { Padding = UDim.new(0, 8), FillDirection = Enum.FillDirection.Horizontal, VerticalAlignment = Enum.VerticalAlignment.Center, SortOrder = Enum.SortOrder.LayoutOrder }, headLeft) braid(headLeft, 34, 16, 16, 3) text(headLeft, "Weave", 16, "text", { bold = true, size = UDim2.fromOffset(50, 24), wrap = false }) local betaTag = new("TextLabel", { Size = UDim2.fromOffset(32, 16), Text = "Beta", TextSize = 10.5, Font = Enum.Font.BuilderSansMedium, LayoutOrder = nextOrder() }, headLeft) round(betaTag, "full") paint(betaTag, "BackgroundColor3", "track") paint(betaTag, "TextColor3", "muted") local pill = new("Frame", { Size = UDim2.fromOffset(0, 22), AutomaticSize = Enum.AutomaticSize.X, AnchorPoint = Vector2.new(1, 0.5), Position = UDim2.new(1, 0, 0.5, 0) }, head) paint(pill, "BackgroundColor3", "track") round(pill, "full") pad(pill, 9, 0) new("UIListLayout", { Padding = UDim.new(0, 6), FillDirection = Enum.FillDirection.Horizontal, VerticalAlignment = Enum.VerticalAlignment.Center, SortOrder = Enum.SortOrder.LayoutOrder }, pill) local pillDot = new("Frame", { Size = UDim2.fromOffset(7, 7), LayoutOrder = 1 }, pill) round(pillDot, "full") paint(pillDot, "BackgroundColor3", "faint") local pillText = new("TextLabel", { Size = UDim2.fromOffset(0, 22), AutomaticSize = Enum.AutomaticSize.X, BackgroundTransparency = 1, TextSize = 11.5, Font = Enum.Font.BuilderSansMedium, LayoutOrder = 2, Text = "Waiting" }, pill) paint(pillText, "TextColor3", "muted") local tab = "sync" local renderTabs local tabRefresh = segmented(root, { { "sync", "Sync" }, { "activity", "Activity" }, { "settings", "Settings" } }, function() return tab end, function(v) tab = v renderTabs() end) local syncPage = column(root, 10) local activityPage = column(root, 10) local settingsPage = column(root, 8) local waitCard = card(syncPage, 10) local heroWrap = new("Frame", { Size = UDim2.new(1, 0, 0, 40), BackgroundTransparency = 1, LayoutOrder = nextOrder() }, waitCard) new("UIListLayout", { HorizontalAlignment = Enum.HorizontalAlignment.Center, VerticalAlignment = Enum.VerticalAlignment.Center }, heroWrap) braid(heroWrap, 150, 36, 26, 5) text(waitCard, "Waiting for your code editor", 15, "text", { medium = true, align = Enum.TextXAlignment.Center }) text(waitCard, "Works with VS Code, Cursor and Windsurf.", 12, "muted", { align = Enum.TextXAlignment.Center }) local function step(parent, n, label) local r = new("Frame", { Size = UDim2.new(1, 0, 0, 0), AutomaticSize = Enum.AutomaticSize.Y, BackgroundTransparency = 1, LayoutOrder = nextOrder() }, parent) local bubble = new("TextLabel", { Size = UDim2.fromOffset(20, 20), Text = tostring(n), TextSize = 11.5, Font = Enum.Font.BuilderSansMedium }, r) round(bubble, "full") paint(bubble, "BackgroundColor3", "track") paint(bubble, "TextColor3", "muted") local l = text(r, label, 12.5, "text", { size = UDim2.new(1, -28, 0, 0) }) l.AutomaticSize = Enum.AutomaticSize.Y l.Position = UDim2.fromOffset(28, 2) end step(waitCard, 1, "Get the Weave extension for your editor") copyBox(waitCard, DOWNLOAD) step(waitCard, 2, "Open your project folder and press Start Weave") step(waitCard, 3, "This panel connects by itself") local connectMsg = text(waitCard, "", 12, "warn") connectMsg.Visible = false local connectButton = button(waitCard, "Connect", "ghost", function() Link.connect() end, 1) local needCard = card(syncPage) local needTitle = text(needCard, "", 15, "text", { medium = true }) local needText = text(needCard, "", 12.5, "muted") local needACall, needBCall = nil, nil local needA = button(needCard, "", "primary", function() if needACall then needACall() end end, 1) local needB = button(needCard, "", "ghost", function() if needBCall then needBCall() end end, 1) local liveWrap = column(syncPage, 10) local liveCard = card(liveWrap, 10) local flow = new("Frame", { Size = UDim2.new(1, 0, 0, 28), BackgroundTransparency = 1, LayoutOrder = nextOrder() }, liveCard) local flowLine = new("Frame", { Size = UDim2.new(1, -40, 0, 2), Position = UDim2.new(0, 20, 0.5, -1) }, flow) paint(flowLine, "BackgroundColor3", "edge") local flowPulse = new("Frame", { Size = UDim2.fromOffset(26, 2), Position = UDim2.new(0, 0, 0, 0), BackgroundTransparency = 1 }, flowLine) paint(flowPulse, "BackgroundColor3", "accent") local function flowNode(xScale, anchor, label) local n = new("TextLabel", { Size = UDim2.fromOffset(0, 24), AutomaticSize = Enum.AutomaticSize.X, AnchorPoint = Vector2.new(anchor, 0.5), Position = UDim2.new(xScale, 0, 0.5, 0), Text = label, TextSize = 11.5, Font = Enum.Font.BuilderSansMedium, ZIndex = 2, }, flow) round(n, "full") pad(n, 9, 0) edge(n) paint(n, "BackgroundColor3", "track") paint(n, "TextColor3", "text") return n end flowNode(0, 0, "Studio") local flowFolder = flowNode(0.5, 0.5, "Folder") local flowPeople = flowNode(1, 1, "Just you") local stats = new("Frame", { Size = UDim2.new(1, 0, 0, 40), BackgroundTransparency = 1, LayoutOrder = nextOrder() }, liveCard) new("UIListLayout", { FillDirection = Enum.FillDirection.Horizontal, SortOrder = Enum.SortOrder.LayoutOrder }, stats) local function stat(label) local t = new("Frame", { Size = UDim2.fromScale(1 / 2, 1), BackgroundTransparency = 1, LayoutOrder = nextOrder() }, stats) new("UIListLayout", { SortOrder = Enum.SortOrder.LayoutOrder }, t) local v = text(t, "0", 18, "text", { bold = true, size = UDim2.new(1, -6, 0, 24), wrap = false }) text(t, label, 11, "faint", { size = UDim2.new(1, -6, 0, 14), wrap = false }) return v end local statScripts = stat("Scripts in sync") local statLast = stat("Last change") local whereNote = text(liveCard, "", 12, "warn") whereNote.Visible = false local function say(message) whereNote.Text = message or "" whereNote.Visible = message ~= nil end local whereButtons = row(liveCard, 8, 32) button(whereButtons, "Open folder", "ghost", function() say(nil) Link.command("openFolder") end, 0.5) button(whereButtons, "Open in editor", "ghost", function() say(nil) local res = Link.command("openEditor") if not res.ok then say(tostring(res.error)) end end, 0.5) local alert = card(liveWrap) local alertTitle = text(alert, "", 13.5, "warn", { medium = true }) local alertText = text(alert, "", 12.5, "muted") local alertRow = row(alert, 8, 32) button(alertRow, "Apply to Studio", "primary", function() Link.command("release", { accept = true }) end, 0.5) button(alertRow, "Put the files back", "ghost", function() Link.command("release", { accept = false }) end, 0.5) local peopleCard = card(activityPage) text(peopleCard, "Here now", 13, "text", { medium = true }) local peopleRows = {} for _ = 1, 8 do local r = row(peopleCard, 8, 20) local dot = new("Frame", { Size = UDim2.fromOffset(8, 8), LayoutOrder = nextOrder() }, r) round(dot, "full") local l = text(r, "", 12.5, "muted", { size = UDim2.new(1, -16, 1, 0), wrap = false }) r.Visible = false table.insert(peopleRows, { row = r, dot = dot, label = l }) end local function feedList(parent, count) local c = card(parent, 6) text(c, "Latest changes", 13, "text", { medium = true }) local empty = text(c, "Nothing yet. Edit a script here or in your editor.", 12.5, "faint") local rows = {} for _ = 1, count do local r = row(c, 7, 20) local dot = new("Frame", { Size = UDim2.fromOffset(7, 7), LayoutOrder = nextOrder() }, r) round(dot, "full") paint(dot, "BackgroundColor3", "faint") local name = text(r, "", 12.5, "text", { size = UDim2.new(1, -106, 1, 0), wrap = false }) local where = text(r, "", 11.5, "faint", { size = UDim2.fromOffset(86, 20), wrap = false, align = Enum.TextXAlignment.Right }) r.Visible = false table.insert(rows, { row = r, dot = dot, name = name, where = where }) end return { empty = empty, rows = rows } end local feedShort = feedList(liveWrap, 3) local feedLong = feedList(activityPage, 6) local activityHint = text(activityPage, "Connect to see changes, people and versions.", 12, "faint") local histCard = card(activityPage) local histTitle = text(histCard, "", 13, "text", { medium = true, wrap = false }) local histEmpty = text(histCard, "No earlier versions yet.", 12.5, "faint") local histRows = {} local panelState = nil local receivedAt = os.clock() local histKey = nil local histAt = 0 local refreshHistory for _ = 1, 3 do local r = row(histCard, 6, 28) local l = text(r, "", 12, "muted", { size = UDim2.new(1, -76, 1, 0), wrap = false }) local entry = { row = r, label = l, at = nil } local b = button(r, "Restore", "ghost", function() if not entry.at or not histKey then return end Link.command("restore", { key = histKey, at = entry.at }) histAt = 0 refreshHistory() end) b.Size = UDim2.fromOffset(70, 26) b.AutomaticSize = Enum.AutomaticSize.None r.Visible = false entry.button = b table.insert(histRows, entry) end local skippedCard = card(activityPage) local skippedTitle = text(skippedCard, "", 13, "warn", { medium = true }) local skippedText = text(skippedCard, "", 12, "muted") local opts = { services = {}, instances = {}, all = {}, protect = true, layout = "weave", first = false, team = "off" } local pending = {} local pendingAt = 0 local applying = false local section = nil local renderSettings local settingsList = column(settingsPage, 6) local settingsBack = new("TextButton", { Size = UDim2.new(1, 0, 0, 24), BackgroundTransparency = 1, Text = "‹ Settings", TextSize = 13, Font = Enum.Font.BuilderSansMedium, TextXAlignment = Enum.TextXAlignment.Left, LayoutOrder = nextOrder(), Visible = false }, settingsPage) paint(settingsBack, "TextColor3", "muted") settingsBack.MouseButton1Click:Connect(function() section = nil renderSettings() end) local settingsLive = column(settingsPage, 8) local settingsNote = text(settingsPage, "", 12, "warn") settingsNote.Visible = false local settingsHint = text(settingsPage, "The rest appears once Weave is connected.", 12, "faint") local function sendOptions() local mine = pendingAt task.wait(0.7) if mine ~= pendingAt or applying then return end local patch = pending pending = {} applying = true local res = Link.command("setOptions", patch) applying = false settingsNote.Text = res.ok and "" or tostring(res.error) settingsNote.Visible = not res.ok if next(pending) then pendingAt += 1 task.spawn(sendOptions) end end local function change(key, value) opts[key] = value pending[key] = value pendingAt += 1 task.spawn(sendOptions) end local function has(list, name) return table.find(list, name) ~= nil end local function checkGrid(parent, key) local holder = new("Frame", { Size = UDim2.fromScale(1, 0), AutomaticSize = Enum.AutomaticSize.Y, BackgroundTransparency = 1, LayoutOrder = nextOrder() }, parent) new("UIGridLayout", { CellSize = UDim2.new(0.5, -4, 0, 24), CellPadding = UDim2.fromOffset(8, 2), SortOrder = Enum.SortOrder.LayoutOrder }, holder) local rows = {} local function refresh() for i, name in ipairs(opts.all) do local entry = rows[i] if not entry then local b = new("TextButton", { BackgroundTransparency = 1, Text = "", LayoutOrder = i }, holder) local box = new("Frame", { Size = UDim2.fromOffset(14, 14), AnchorPoint = Vector2.new(0, 0.5), Position = UDim2.new(0, 0, 0.5, 0) }, b) round(box, 4) local tick = new("TextLabel", { Size = UDim2.fromScale(1, 1), BackgroundTransparency = 1, Text = "✓", TextSize = 11, Font = Enum.Font.BuilderSansBold }, box) local l = new("TextLabel", { Size = UDim2.new(1, -20, 1, 0), Position = UDim2.fromOffset(20, 0), BackgroundTransparency = 1, TextSize = 12, Font = Enum.Font.BuilderSans, TextXAlignment = Enum.TextXAlignment.Left, TextTruncate = Enum.TextTruncate.AtEnd }, b) paint(l, "TextColor3", "text") paint(tick, "TextColor3", "ink") entry = { b = b, box = box, tick = tick, l = l } rows[i] = entry b.MouseButton1Click:Connect(function() local list = table.clone(opts[key]) local at = table.find(list, opts.all[i]) if at then table.remove(list, at) else table.insert(list, opts.all[i]) end if key == "services" and #list == 0 then return end change(key, list) refresh() end) end entry.l.Text = name local on = has(opts[key], name) entry.tick.Visible = on paint(entry.box, "BackgroundColor3", on and "fill" or "thumb") end end return refresh end local whatCard = card(settingsLive) text(whatCard, "Scripts", 13, "text", { medium = true }) text(whatCard, "Sync scripts in these places.", 11.5, "faint") local refreshServices = checkGrid(whatCard, "services") local partsCard = card(settingsLive) local partsGridWrap local refreshPartsSwitch = switchRow(partsCard, "Also sync parts and UI", "Off keeps it to code, like Rojo. On syncs other instances between Studios, not to files.", function() return #opts.instances > 0 end, function(on) change("instances", on and { "StarterGui", "ReplicatedStorage" } or {}) partsGridWrap.Visible = on end) partsGridWrap = column(partsCard, 4) local refreshInstances = checkGrid(partsGridWrap, "instances") local safeCard = card(settingsLive) local refreshProtect = switchRow(safeCard, "Block stale overwrites", "Stops an old copy of a script, pushed by Rojo or Team Create, replacing newer work.", function() return opts.protect end, function(on) change("protect", on) end) text(safeCard, "When both sides differ on first sync", 12.5, "muted") local refreshFirst = segmented(safeCard, { { false, "Ask me" }, { "studio", "Studio" }, { "files", "Folder" } }, function() return opts.first end, function(v) change("first", v) end) text(safeCard, "Pause when this many scripts vanish or shrink at once", 12.5, "muted") local holdBox = inputBox(safeCard, "25", true) holdBox.FocusLost:Connect(function() local n = tonumber(holdBox.Text) if n and n >= 5 and n <= 1000 and n % 1 == 0 then change("holdLimit", n) end holdBox.Text = tostring(opts.holdLimit or 25) end) local folderCard = card(settingsLive) text(folderCard, "Folder", 13, "text", { medium = true }) text(folderCard, "New projects use", 12.5, "muted") local refreshLayout = segmented(folderCard, { { "weave", "Plain folders" }, { "rojo", "Rojo style (src)" } }, function() return opts.layout end, function(v) change("layout", v) end) local refreshSourcemap = switchRow(folderCard, "Write sourcemap.json", "For luau-lsp, so requires resolve in your editor.", function() return opts.sourcemap == true end, function(on) change("sourcemap", on) end) local folderGaps = text(folderCard, "", 12, "warn") folderGaps.Visible = false button(folderCard, "Edit the ignore list", "ghost", function() Link.command("openIgnore") end, 1) local folderInput = inputBox(folderCard, "Use another folder: paste its path") folderInput.FocusLost:Connect(function(enter) if not enter or folderInput.Text == "" then return end local res = Link.command("setFolder", { path = folderInput.Text }) folderInput.Text = "" settingsNote.Text = res.ok and "" or tostring(res.error) settingsNote.Visible = not res.ok if res.ok then Link.reconnect() end end) local teamCard = card(settingsLive) text(teamCard, "Teammates", 13, "text", { medium = true }) local teamHint = text(teamCard, "", 12, "faint") local teamCodeWrap local joinBox local refreshTeam = segmented(teamCard, { { "off", "Just me" }, { "host", "Invite" }, { "join", "Join" } }, function() return opts.team end, function(v) opts.team = v teamCodeWrap.Visible = false joinBox.Visible = v == "join" if v ~= "join" then pending.team = v == "host" and { mode = "host" } or false pendingAt += 1 task.spawn(sendOptions) end end) teamCodeWrap = column(teamCard, 4) local teamBox = copyBox(teamCodeWrap, "") teamCodeWrap.Visible = false joinBox = inputBox(teamCard, "Paste the join code and press Enter", true) joinBox.Visible = false joinBox.FocusLost:Connect(function(enter) if enter and joinBox.Text ~= "" then pending.team = { mode = "join", code = joinBox.Text } pendingAt += 1 task.spawn(sendOptions) end end) local pluginCard = card(settingsLive) local refreshAuto = switchRow(pluginCard, "Connect automatically", nil, function() return Link.auto end, function(on) Link.setAuto(on) end) local portRow = row(pluginCard, 8, 30) text(portRow, "Port", 13, "text", { size = UDim2.new(1, -86, 1, 0), wrap = false }) local portBox = new("TextBox", { Size = UDim2.fromOffset(78, 26), Text = tostring(Link.port), TextSize = 12, Font = Enum.Font.RobotoMono, ClearTextOnFocus = false, LayoutOrder = nextOrder() }, portRow) round(portBox, 8) edge(portBox) paint(portBox, "BackgroundColor3", "bg") paint(portBox, "TextColor3", "text") portBox.FocusLost:Connect(function() local n = tonumber(portBox.Text) if n and n >= 1 and n <= 65535 and n % 1 == 0 then Link.setPort(n) end portBox.Text = tostring(Link.port) end) local disconnectButton = button(pluginCard, "Disconnect", "ghost", function() Link.disconnect() end, 1) local SECTIONS = { { label = "Scripts", card = whatCard, live = true }, { label = "Parts and UI", card = partsCard, live = true }, { label = "Safety", card = safeCard, live = true }, { label = "Folder", card = folderCard, live = true }, { label = "Teammates", card = teamCard, live = true }, { label = "This plugin", card = pluginCard, live = false }, } for _, s in ipairs(SECTIONS) do local b = new("TextButton", { Size = UDim2.new(1, 0, 0, 36), Text = "", AutoButtonColor = false, LayoutOrder = nextOrder() }, settingsList) round(b, 10) edge(b) paint(b, "BackgroundColor3", "card") local l = new("TextLabel", { Size = UDim2.new(0.5, 0, 1, 0), Position = UDim2.fromOffset(12, 0), BackgroundTransparency = 1, Text = s.label, TextSize = 13, Font = Enum.Font.BuilderSansMedium, TextXAlignment = Enum.TextXAlignment.Left }, b) paint(l, "TextColor3", "text") s.value = new("TextLabel", { Size = UDim2.new(0.5, -28, 1, 0), Position = UDim2.fromScale(0.5, 0), BackgroundTransparency = 1, Text = "", TextSize = 12, Font = Enum.Font.BuilderSans, TextXAlignment = Enum.TextXAlignment.Right, TextTruncate = Enum.TextTruncate.AtEnd }, b) paint(s.value, "TextColor3", "faint") local chev = new("TextLabel", { Size = UDim2.fromOffset(16, 36), AnchorPoint = Vector2.new(1, 0), Position = UDim2.new(1, -8, 0, 0), BackgroundTransparency = 1, Text = "›", TextSize = 16 }, b) paint(chev, "TextColor3", "faint") s.button = b b.MouseButton1Click:Connect(function() section = s renderSettings() end) end local function ago(s) if not s then return "None yet" end if s < 10 then return "Just now" end if s < 60 then return tostring(math.floor(s)) .. " s ago" end if s < 3600 then return tostring(math.floor(s / 60)) .. " min ago" end return tostring(math.floor(s / 3600)) .. " h ago" end local function shortPath(p) local parts = string.split(tostring(p or ""), ".") if #parts <= 2 then return tostring(p or "") end return parts[#parts - 1] .. "." .. parts[#parts] end local function keyName(key) local parts = string.split(tostring(key or ""), "/") local last = parts[#parts] or "" return (string.gsub(string.gsub(last, "%%2F", "/"), "%%25", "%%")) end local function plural(n, word) return tostring(n) .. " " .. word .. (n == 1 and "" or "s") end local function renderPeople() local p = W.people or {} local list = type(p.people) == "table" and p.people or {} flowPeople.Text = #list > 0 and tostring(#list + 1) .. " people" or "Just you" peopleCard.Visible = #list > 0 for i, entry in ipairs(peopleRows) do local person = list[i] entry.row.Visible = person ~= nil if person then local okColor, color = pcall(Color3.fromHex, tostring(person.color or "417dfc")) entry.dot.BackgroundColor3 = okColor and color or Color3.fromHex("417dfc") local bits = { tostring(person.name or "Someone") } if person.path then table.insert(bits, shortPath(person.path)) end if person.where then table.insert(bits, tostring(person.where)) end if person.typing then table.insert(bits, "typing") end if person.key and W.activeKey and person.key == W.activeKey then table.insert(bits, "in your script") end entry.label.Text = table.concat(bits, " · ") end end end refreshHistory = function() local key = W.activeKey if Link.state ~= "on" or not key then histCard.Visible = false histKey = nil return end if key == histKey and os.clock() - histAt < 5 then return end histKey = key histAt = os.clock() histCard.Visible = true histTitle.Text = "Versions of " .. keyName(key) local res = Link.command("history", { key = key }) if key ~= W.activeKey then return end local versions = type(res.versions) == "table" and res.versions or {} histEmpty.Visible = #versions <= 1 for i, entry in ipairs(histRows) do local v = i > 1 and versions[i] or nil entry.row.Visible = v ~= nil if v then entry.at = v.at entry.label.Text = tostring(v.by or "Someone") .. " · " .. tostring(v.where or "") .. " · " .. string.lower(ago(v.ago)) entry.button.Visible = not v.gone end end end local function renderOptions() local s = panelState or {} if type(s.options) == "table" and not next(pending) and not applying then local o = s.options opts.services = o.services or opts.services opts.instances = o.instances or {} opts.all = o.all or opts.all opts.protect = o.protect ~= false opts.layout = o.layout or "weave" opts.first = o.first or false opts.team = o.team or "off" opts.sourcemap = o.sourcemap == true opts.holdLimit = o.holdLimit end refreshServices() refreshInstances() refreshPartsSwitch() partsGridWrap.Visible = #opts.instances > 0 refreshProtect() refreshFirst() refreshLayout() refreshSourcemap() refreshTeam() holdBox.Text = holdBox:IsFocused() and holdBox.Text or tostring(opts.holdLimit or 25) folderGaps.Text = s.gaps or "" folderGaps.Visible = s.gaps ~= nil and s.gaps ~= "" local codes = type(s.codes) == "table" and s.codes or {} teamCodeWrap.Visible = opts.team == "host" and #codes > 0 joinBox.Visible = opts.team == "join" and not (s.team and s.team.state == "live") if #codes > 0 then teamBox.Text = tostring(codes[1].code) end if opts.team == "host" then teamHint.Text = "Send this code to teammates on your network. They paste it under Join." elseif opts.team == "join" then teamHint.Text = s.team and s.team.state == "live" and "You're in. Edits merge as you type." or "Ask the person inviting you for their code." else teamHint.Text = "Sync with other people on your network." end end local function renderLive() local s = panelState or {} local elapsed = os.clock() - receivedAt statScripts.Text = tostring(s.scripts or 0) statLast.Text = s.lastSync and ago(s.lastSync + elapsed) or "None yet" statLast.TextSize = 15 flowFolder.Text = tostring(s.folder or (Link.info and Link.info.folder) or "Folder") local held, guard, refused, failure = s.held, s.guard, s.refused, s.error alertRow.Visible = held ~= nil alert.Visible = held ~= nil or guard ~= nil or refused ~= nil or failure ~= nil if held then alertTitle.Text = "Weave held a big change" alertText.Text = plural(held.removed or 0, "script") .. " removed and " .. tostring(held.changed or 0) .. " cut down in the folder at once, which often means a branch switch. Studio hasn't changed." elseif refused then alertTitle.Text = refused.why == "read" and "You can view but not edit" or "That script is locked" alertText.Text = "Your change to " .. tostring(refused.path or "that script") .. " was put back." elseif guard then alertTitle.Text = plural(guard.count or 0, "script") .. " came back" alertText.Text = "They were missing from the " .. tostring(guard.where) .. " when Weave connected, so it restored them instead of deleting them everywhere. Delete them while connected if you meant to." elseif failure then alertTitle.Text = "Something went wrong" alertText.Text = tostring(failure) end local feed = type(s.feed) == "table" and s.feed or {} for _, list in ipairs({ feedShort, feedLong }) do list.empty.Visible = #feed == 0 for i, entry in ipairs(list.rows) do local f = feed[i] entry.row.Visible = f ~= nil if f then entry.name.Text = shortPath(f.path) paint(entry.dot, "BackgroundColor3", SOURCE_COLOR[f.where] or "faint") entry.where.Text = tostring(f.by or f.where or "") .. " · " .. string.gsub(string.lower(ago((f.ago or 0) + elapsed)), " ago", "") end end end local skipped = type(s.skipped) == "table" and s.skipped or {} skippedCard.Visible = #skipped > 0 if #skipped > 0 then skippedTitle.Text = plural(#skipped, "script") .. " not synced" local lines = {} for i = 1, math.min(4, #skipped) do table.insert(lines, tostring(skipped[i].path) .. ": " .. tostring(skipped[i].why)) end skippedText.Text = table.concat(lines, "\n") end renderPeople() if tab == "settings" then renderOptions() renderSettings() end end local function setPill(label, key) pillText.Text = label paint(pillDot, "BackgroundColor3", key) end local function renderNeed() local n = Link.need or {} needB.Visible = true if n.need == "first" then needTitle.Text = "Which side starts as the truth?" needText.Text = tostring(n.folder) .. " has " .. plural(n.folderScripts or 0, "script") .. " and " .. tostring(n.place) .. " has " .. plural(n.studioScripts or 0, "script") .. ". Where a script differs, the side you pick wins this once. The other version is saved in a backup on your PC, and scripts on only one side reach both." needA.Text = "Start from Studio" needB.Text = "Start from the folder" needACall = function() Link.state = "off" Link.connect({ first = "studio" }) end needBCall = function() Link.state = "off" Link.connect({ first = "files" }) end elseif n.need == "link" then needTitle.Text = "This folder belongs to another place" needText.Text = tostring(n.folder) .. " is linked to " .. tostring(n.linked) .. ", and you opened " .. tostring(n.place) .. ". Linking this place replaces its differing scripts with the folder's versions and saves the old ones in a backup on your PC." needA.Text = "Link this place" needB.Text = "Cancel" needACall = function() Link.state = "off" Link.connect({ relink = true }) end needBCall = Link.cancelNeed elseif n.need == "busy" then needTitle.Text = "Weave is busy" needText.Text = "It's connected to " .. tostring(n.name) .. " in another Studio window. Disconnect there first." needA.Text = "Try again" needB.Text = "Cancel" needACall = function() Link.state = "off" Link.connect() end needBCall = Link.cancelNeed else if n.need == "place" then needTitle.Text = "This project is for another place" needText.Text = "Its project file lists the places it may sync to with servePlaceIds, and this isn't one of them. Open the right place, or add this one's id to the list." needA.Text = "Try again" needB.Visible = false needACall = function() Link.state = "off" Link.connect() end return end needTitle.Text = "Update Weave" needText.Text = "This plugin and your Weave extension are different versions. Update both from rodexai.dev/weave." needA.Text = "Try again" needB.Visible = false needACall = function() Link.state = "off" Link.connect() end end end renderSettings = function() local on = Link.state == "on" if section and section.live and not on then section = nil end settingsList.Visible = section == nil settingsBack.Visible = section ~= nil settingsHint.Visible = section == nil and not on settingsLive.Visible = section ~= nil for _, s in ipairs(SECTIONS) do s.card.Visible = section == s s.button.Visible = on or not s.live end disconnectButton.Visible = on SECTIONS[1].value.Text = tostring(#opts.services) .. " places" SECTIONS[2].value.Text = #opts.instances > 0 and "On" or "Off" SECTIONS[3].value.Text = opts.protect and "Protected" or "Off" SECTIONS[4].value.Text = tostring((panelState and panelState.folder) or "") SECTIONS[5].value.Text = opts.team == "host" and "Inviting" or opts.team == "join" and "Joined" or "Just me" SECTIONS[6].value.Text = Link.auto and "Connects by itself" or "Manual" end renderTabs = function() syncPage.Visible = tab == "sync" activityPage.Visible = tab == "activity" settingsPage.Visible = tab == "settings" tabRefresh() if tab == "settings" then renderOptions() renderSettings() end end local function render() local state = Link.state waitCard.Visible = state == "off" or state == "connecting" needCard.Visible = state == "need" liveWrap.Visible = state == "on" activityHint.Visible = state ~= "on" if state ~= "on" then peopleCard.Visible = false skippedCard.Visible = false histCard.Visible = false end feedLong.empty.Parent.Visible = state == "on" if tab == "settings" then renderSettings() end connectButton.Text = state == "connecting" and "Connecting" or "Connect" connectButton.Visible = not Link.auto heroWrap.Visible = Link.auto connectMsg.Text = Link.message or "" connectMsg.Visible = Link.message ~= nil and Link.message ~= "" refreshAuto() if state == "on" then setPill("Live", "ok") renderLive() elseif state == "connecting" then setPill("Connecting", "warn") elseif state == "need" then setPill("Your call", "warn") renderNeed() else setPill(Link.auto and "Waiting" or "Off", "faint") end end local lastFeed = nil local waitUntil = os.clock() + 20 local QUIET_NEEDS = { link = true, busy = true, place = true } local wasHeld = false onChange = function() if Link.state ~= "on" then waitUntil = os.clock() + 20 end if Link.state == "need" and Link.need then if QUIET_NEEDS[Link.need.need] then warn("Weave isn't syncing this place. Click Weave in the toolbar to see why.") else widget.Enabled = true end end render() end onPanel = function(state) panelState = state local held = state.held ~= nil if held and not wasHeld then widget.Enabled = true end wasHeld = held receivedAt = os.clock() local top = type(state.feed) == "table" and state.feed[1] local stamp = top and tostring(top.path) .. tostring(state.lastSync) or nil if stamp ~= lastFeed then lastFeed = stamp W.activeUntil = os.clock() + 1.6 histAt = 0 end render() end W.onPresence = function() if Link.state == "on" then render() end end local phase = 0.6 local acc = 0 local conn = RunService.Heartbeat:Connect(function(dt) if not widget.Enabled then return end acc += dt if acc < 0.05 then return end dt = acc acc = 0 local now = os.clock() local busy = now < (W.activeUntil or 0) local waiting = (Link.state == "off" or Link.state == "connecting") and now < waitUntil if busy or waiting then phase += dt * (busy and 3.4 or 1) for _, b in ipairs(braids) do if b.holder.AbsoluteSize.X > 0 then b.set(phase) end end end if busy and Link.state == "on" then flowPulse.BackgroundTransparency = 0 local t = (now * 0.9) % 1 flowPulse.Position = UDim2.new(t, -13, 0, 0) elseif flowPulse.BackgroundTransparency ~= 1 then flowPulse.BackgroundTransparency = 1 end end) local ticker = true task.spawn(function() while ticker do task.wait(2) if Link.state == "on" and widget.Enabled then pcall(renderLive) pcall(refreshHistory) end end end) local themeConn = Studio.ThemeChanged:Connect(function() P = PALETTES[themeName()] for inst, props in pairs(themed) do for prop, key in pairs(props) do inst[prop] = Color3.fromHex(P[key]) end end end) plugin.Unloading:Connect(function() ticker = false conn:Disconnect() themeConn:Disconnect() end) histCard.Visible = false alert.Visible = false renderTabs() render() end plugin.Unloading:Connect(function() if Link.state == "on" then local client = Link.client task.spawn(function() Link.request("POST", "/weave/bye", { k = client }) end) end Link.gen += 1 stopWatching() alive = false for _, c in ipairs(tracked) do pcall(function() c:Disconnect() end) end end) if Link.auto then task.delay(1, function() Link.connect({ quiet = true }) end) end ]]>