### Markdown Fenced Code Block Example Source: https://github.com/robloxapi/doc/blob/master/man/writing.md Demonstrates how to create a fenced code block in Markdown, specifying 'lua' for syntax highlighting. This is useful for including code examples within the documentation. ```markdown ```lua -- Example Lua code local function greet(name) print("Hello, " .. name .. "!") end ``` ``` -------------------------------- ### Markdown Table Example Source: https://github.com/robloxapi/doc/blob/master/man/writing.md Illustrates the syntax for creating a simple table in Markdown, including column headers and rows. This is used for presenting structured data clearly. ```markdown column 1 | column 2 | column 3 ---------|----------|--------- cell 1 | cell 2 | cell 3 cell 4 | cell 5 | cell 6 ``` -------------------------------- ### HttpService GetAsync Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/HttpService.md Sends a GET request to a website. This is a shorthand for making GET requests. ```APIDOC ## GET /robloxapi/getasync ### Description Sends a GET request to a specified URL and returns the response body as a string. ### Method `GET` ### Endpoint `/robloxapi/getasync` ### Parameters #### Query Parameters - **url** (string) - Required - The URL to send the GET request to. ### Request Example ```json { "url": "https://api.example.com/resource" } ``` ### Response #### Success Response (200) - **body** (string) - The response body from the server. #### Response Example ```json { "body": "{\"data\": \"example data\"}" } ``` ``` -------------------------------- ### GetAsync Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/HttpService.md Makes an HTTP GET request to a specified URL. Supports optional caching control and custom headers. Throws an error for non-successful status codes. ```APIDOC ## GET /robloxapi/doc/GetAsync ### Description Sends a GET request to a URL. Can optionally disable caching and include custom headers. ### Method GET ### Endpoint /robloxapi/doc/GetAsync ### Parameters #### Query Parameters - **url** (string) - Required - The URL to send the request to. - **nocache** (boolean) - Optional - If true, sets the `Cache-Control` header to `no-cache`. - **headers** (table) - Optional - A table of HTTP headers to include in the request. ### Request Example ```json { "url": "https://example.com/data", "nocache": true, "headers": { "Authorization": "Bearer token" } } ``` ### Response #### Success Response (200) - **body** (string) - The body of the HTTP response. #### Response Example ```json { "body": "{\"message\": \"Success\"}" } ``` ### Error Handling - Throws an error with the format `HTTP 000 (MESSAGE)` for non-successful status codes. ``` -------------------------------- ### HttpService - Making HTTP Requests in Lua Source: https://context7.com/robloxapi/doc/llms.txt Demonstrates how to use Roblox's HttpService to make HTTP requests from game servers. This includes GET and POST requests, handling responses, JSON encoding/decoding, and generating GUIDs. Ensure HTTP requests are enabled in game settings. ```lua -- Make a GET request to fetch JSON data from an API local HttpService = game:GetService("HttpService") -- Enable HTTP requests in game settings first if not HttpService.HttpEnabled then warn("HTTP requests are not enabled") return end -- GET request using RequestAsync (recommended) local success, result = pcall(function() return HttpService:RequestAsync({ Url = "https://api.example.com/data", Method = "GET", Headers = { ["Accept"] = "application/json" } }) end) if success and result.Success then print("Status:", result.StatusCode) print("Body:", result.Body) -- Decode JSON response local data = HttpService:JSONDecode(result.Body) print("Parsed data:", data.name) else warn("Request failed:", result) end -- POST request with JSON body local postData = { username = "player123", score = 1000 } local success, result = pcall(function() return HttpService:RequestAsync({ Url = "https://api.example.com/scores", Method = "POST", Headers = { ["Content-Type"] = "application/json" }, Body = HttpService:JSONEncode(postData) }) end) if success and result.Success then print("Score submitted successfully") else warn("Failed to submit score:", result.StatusMessage) end -- Generate UUID local guid = HttpService:GenerateGUID(false) print("Generated UUID:", guid) -- e.g., "550e8400-e29b-41d4-a716-446655440000" ``` -------------------------------- ### C Declaration Syntax Example Source: https://github.com/robloxapi/doc/blob/master/man/typedec.md Demonstrates the traditional C syntax for declaring a variable, where the type precedes the variable name. This is presented as a contrast to the L2R syntax described in the document. ```c // C syntax int name = 42; ``` -------------------------------- ### Example of Type Declaration for Struct Method Source: https://github.com/robloxapi/doc/blob/master/man/writing.md This markdown snippet shows the specific format for a type declaration within a struct's section, used to document methods like Lerp. ```markdown ## `Lerp(goal: CFrame, alpha: number): CFrame` ``` -------------------------------- ### Markdown for Entity Documentation Structure Source: https://github.com/robloxapi/doc/blob/master/man/writing.md This markdown code demonstrates the typical section hierarchy for documenting an entity in the Roblox API, including Summary, Details, and Examples. ```markdown # Entity ## Summary This content is treated as the summary. ## Details This content is treated as the details. ``` -------------------------------- ### Roblox API Methods Source: https://github.com/robloxapi/doc/blob/master/man/writing.md Outlines the methods provided by Roblox API types. Method identifiers start with 'method-' followed by the case-sensitive method name. ```markdown # Methods ## `Inverse(): CFrame` ## `Lerp(goal: CFrame, alpha: number): CFrame` ## `ToWorldSpace(cf: CFrame): CFrame` ## `ToObjectSpace(cf: CFrame): CFrame` ``` -------------------------------- ### TypeScript Declaration Syntax Example Source: https://github.com/robloxapi/doc/blob/master/man/typedec.md Illustrates the TypeScript syntax for variable declaration, which is also type before name. This is shown to highlight the difference from the L2R syntax used in Roblox API documentation. ```typescript // TypeScript syntax let name: number = 42; ``` -------------------------------- ### Lua API and Pure-Lua Type Declarations Source: https://github.com/robloxapi/doc/blob/master/man/typedec.md Provides examples of declaring types specific to the Roblox API (e.g., 'Vector3', 'Class.BasePart') and general Lua types (e.g., 'number'). It shows how to reference existing API types and standard Lua types. ```lua position: Vector3 math.pi: number part: Class.BasePart surface: Enum.NormalId ``` -------------------------------- ### Unconstrained Lerp Function Example Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/article/Intervals.md Demonstrates an unconstrained Lerp function where the alpha parameter, despite having an interval of [0, 1], can accept values outside this range, resulting in extrapolation rather than clamping or error. ```Lua function Lerp(x, y, alpha) return (1 - alpha) * x + alpha * y end ``` -------------------------------- ### Create and Manage Instances with Weak References in Lua Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/Instance.md Demonstrates creating a new Instance (BoolValue) and attaching it to the game's workspace. It highlights weak reference behavior using a metatable and shows how objects can be garbage collected from a table while remaining in the game tree. ```lua -- Table with weak value references. local weakTable = setmetatable({}, {__mode='v'}) -- Create an object, then add it to the game tree and the weak table. local object = Instance.new("BoolValue") object.Parent = workspace weakTable[1] = object object = nil -- Remove strong reference to the object. print("Reference:", weakTable[1]) --> Reference: Value (userdata still exists) -- Wait until the userdata is collected. while #weakTable > 0 do wait() end print("Reference:", weakTable[1]) --> Reference: nil (userdata was collected) print("Object:", workspace.Value) --> Object: Value (object still exists) ``` -------------------------------- ### Instance.new Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/Instance.md Creates a new instance of a specified class, optionally parenting it to another instance. ```APIDOC ## POST /robloxapi/doc ### Description Creates a new instance of a specified Roblox class. You can optionally provide a parent instance to set the new instance's parent upon creation. Default values for properties are set based on the class definition. ### Method POST ### Endpoint `/robloxapi/doc` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **className** (string) - Required - The name of the class for the new instance. - **parent** (Instance) - Optional - The instance to which the new instance will be parented. ### Request Example ```json { "className": "Part", "parent": "workspace" } ``` ### Response #### Success Response (200) - **Instance** (Instance) - The newly created instance. #### Response Example ```json { "Instance": "Instance(Part)" } ``` ### Errors - **Unable to create an Instance of type "CLASS"**: Thrown if an instance of the specified class cannot be created (e.g., abstract classes, services, or NotCreatable classes). ``` -------------------------------- ### Roblox Instance Management in Lua Source: https://context7.com/robloxapi/doc/llms.txt Demonstrates fundamental operations for Roblox Instances using Lua, including creation, hierarchy manipulation, searching, cloning, and event handling. It highlights efficient instance creation with a parent and safe cleanup using :Destroy(). ```lua local part = Instance.new("Part") part.Name = "MyPart" part.Size = Vector3.new(4, 1, 2) part.Position = Vector3.new(0, 10, 0) part.BrickColor = BrickColor.new("Bright red") part.Parent = workspace -- Adding to game tree local folder = Instance.new("Folder", workspace) folder.Name = "PlayerData" local function printChildren(object, indent) indent = indent or "" for _, child in ipairs(object:GetChildren()) do print(indent .. child.Name .. " (" .. child.ClassName .. ")") printChildren(child, indent .. " ") end end printChildren(workspace) local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:FindFirstChild("Humanoid") local head = character:FindFirstChildOfClass("Part") local animator = character:FindFirstChildWhichIsA("Animator") if part:IsDescendantOf(workspace) then print("Part is in the workspace") end if workspace:IsAncestorOf(part) then print("Workspace contains the part") end local clone = part:Clone() clone.Position = Vector3.new(10, 10, 0) clone.Parent = workspace part:GetPropertyChangedSignal("Position"):Connect(function() print("Part moved to:", part.Position) end) part.AncestryChanged:Connect(function(child, parent) print(child.Name .. " ancestry changed, new parent:", parent) end) workspace.ChildAdded:Connect(function(child) print("New child added to workspace:", child.Name) end) workspace.DescendantAdded:Connect(function(descendant) print("New descendant added:", descendant:GetFullName()) end) local tempPart = Instance.new("Part", workspace) task.wait(5) tempPart:Destroy() local existingPart = workspace:FindFirstChild("MyPart") if existingPart then existingPart.BrickColor = BrickColor.new("Bright blue") end local myModel = workspace:WaitForChild("MyModel", 10) if myModel then print("Model loaded") else warn("Model not found within timeout") end ``` -------------------------------- ### Object Manipulation Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/Instance.md This section details methods for copying properties, managing children, and object identification. ```APIDOC ## Copying Properties ### Description Provides methods to copy property changes between Roblox objects, with options for selective or safe copying. ### Examples **Selective Property Copying:** ```lua local appearance = { Color = true, Material = true, Reflectance = true, Transparency = true, } local original = Instance.new("Part", workspace) local copy = Instance.new("Part", workspace) original.Changed:Connect(function(property) if not appearance[property] then return end copy[property] = original[property] end) original.Position = Vector3.new(8, 0, 0) original.Color = BrickColor.Blue().Color ``` **Safe and Complete Property Copying:** ```lua local original = Instance.new("Part", workspace) local copy = Instance.new("Part", workspace) original.Changed:Connect(function(property) local ok, value = pcall(function() return original[property] end) if not ok then return end copy[property] = value end) copy.Position = Vector3.new(8, 0, 0) original.Color = BrickColor.Blue().Color ``` ``` ```APIDOC ## Object Management Methods ### Description Methods for managing object hierarchies, cloning, and data cost calculation. ### Methods - **ChildAdded**: Fired after a child is added to the object. - **ChildRemoved**: Fired after a child is removed from the object. - **ClearAllChildren**: Removes all of the children from the object. - **Clone**: Creates a deep copy of the object. - **DataCost**: Returns the cost of saving the object to data persistence, in data units. - **DescendantAdded**: Fired after a descendant of the object is added. - **DescendantRemoving**: Fired before a descendant of the object is removed. - **Destroy**: Removes the object and marks it as destroyed, preventing reuse. - **FindFirstAncestor**: Returns the first ancestor of the object whose [Name](member:Name) matches the given name. - **FindFirstAncestorOfClass**: Returns the first ancestor of the object whose [ClassName](member:ClassName) matches the given name. - **FindFirstAncestorWhichIsA**: Returns the first ancestor of the object whose class inherits a class of the given name. - **FindFirstChild**: Returns the first child of the object whose [Name](member:Name) matches the given name. - **FindFirstChildOfClass**: Returns the first child of the object whose [ClassName](member:ClassName) matches the given name. - **FindFirstChildWhichIsA**: Returns the first child of the object whose class inherits a class of the given name. - **GetChildren**: Returns a list of the object's children. - **GetDescendants**: Returns a list of all the descendants of the object. - **GetPropertyChangedSignal**: Returns a [signal](type:RBXScriptSignal) that fires after a property of the given name changes. - **IsAncestorOf**: Returns whether the object is an ancestor of a given object. - **IsDescendantOf**: Returns whether the object is a descendant of a given object. ``` ```APIDOC ## Object Identification and Properties ### Description Methods and properties for identifying object types, relationships, and core attributes. ### Methods & Properties - **ClassName**: Returns the name of the object's class. - **GetDebugId**: Returns a value that uniquely identifies the object. - **GetFullName**: Returns a name formatted according to the ascendants of the object. - **IsA**: Returns whether the object's class inherits from a class of the given name. - **Name**: Specifies a string used to identify the object. The value of Name is constrained to a maximum length of 100 bytes. On assignment, extra bytes are truncated. - **Parent**: Specifies an object that the current object is a child of. ``` -------------------------------- ### Markdown for Members Section Structure Source: https://github.com/robloxapi/doc/blob/master/man/writing.md This markdown code shows how to document members of a primary entity, with each subsection representing a member and containing its own Summary, Details, and Examples. ```markdown # Members ## ChildAdded Summary of ChildAdded. ### Details Details of ChildAdded. ## ChildRemoved Summary of ChildRemoved. ### Details Details of ChildRemoved. ``` -------------------------------- ### PostAsync Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/HttpService.md Sends an HTTP POST request with specified data, content type, and optional compression and headers. Has a data size limit. ```APIDOC ## POST /robloxapi/doc/PostAsync ### Description Sends a POST request to a URL with specified data. Supports custom content type, optional gzip compression, and custom headers. Includes a data size limit. ### Method POST ### Endpoint /robloxapi/doc/PostAsync ### Parameters #### Path Parameters - **url** (string) - Required - The URL to send the request to. - **data** (string) - Required - The body of the request. - **content_type** (string) - Optional - Sets the `Content-Type` header. Should be a value from `HttpContentType` enum. - **compress** (boolean) - Optional - If true, attempts to compress the body with gzip encoding if it shortens the content. - **headers** (table) - Optional - A table of HTTP headers to include in the request. ### Request Example ```json { "url": "https://example.com/submit", "data": "{\"key\": \"value\"}", "content_type": "application/json", "compress": true, "headers": { "X-Custom-Header": "Value" } } ``` ### Response #### Success Response (200) - **body** (string) - The body of the HTTP response. #### Response Example ```json { "body": "{\"status\": \"Received\"}" } ``` ### Error Handling - Throws an error with the format `HTTP 000 (MESSAGE)` for non-successful status codes. - Throws an error `Post data too large. Limit: 1024 KB. Post size: SIZE KB` if data exceeds 1024KB. ``` -------------------------------- ### BrickColor Constructors Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/type/BrickColor.md Provides information on various ways to create BrickColor instances using different parameters. ```APIDOC ## Constructors ## `BrickColor.new(value: number)` Returns the BrickColor for which the Number matches *value*. ### Details If no BrickColors are matched, then the default [Medium stone grey][default] is returned. ## `BrickColor.new(name: string)` Returns the BrickColor for which the Name matches *name*. ### Details If no BrickColors are matched, then the default [Medium stone grey][default] is returned. Some colors share the same name. For such cases, the [BrickColor table](#doc-details) indicates which color is returned for the given name. ## `BrickColor.new(r: number?, g: number?, b: number?)` Returns the BrickColor nearest to the given color components. ### Details Each parameter defaults to 0. "Nearest" is loosely defined. If a given color is nearby multiple BrickColors within a margin of error, one result should not be expected over another. ## `BrickColor.new(color: Color3)` Returns the BrickColor nearest to the given color. ### Details "Nearest" is loosely defined. If a given color is nearby multiple BrickColors within a margin of error, one result should not be expected over another. ## `BrickColor.palette(index: number)` Returns a BrickColor from a predefined list of colors. ### Details The "Palette Index" column in the [BrickColor table](#doc-details) indicates the index of the color in the palette, or that the color is not in the palette, if empty. The palette contains 128 colors. *index* must be between 0 and 127. If *index* is out of this range, then the following error is thrown: pale tte index out of bounds (INDEX) Where `INDEX` is the given value rounded to the nearest integer. ## `BrickColor.random()` Returns a randomly selected BrickColor. ## `BrickColor.White()` Returns the BrickColor [White](#doc-brickcolor-1). ## `BrickColor.Gray()` Returns the BrickColor [Medium stone grey](#doc-brickcolor-194). ## `BrickColor.DarkGray()` Returns the BrickColor [Dark stone grey](#doc-brickcolor-199). ## `BrickColor.Black()` Returns the BrickColor [Black](#doc-brickcolor-26). ## `BrickColor.Red()` Returns the BrickColor [Bright red](#doc-brickcolor-21) ## `BrickColor.Yellow()` Returns the BrickColor [Bright yellow](#doc-brickcolor-24). ## `BrickColor.Green()` Returns the BrickColor [Dark green](#doc-brickcolor-28). ## `BrickColor.Blue()` Returns the BrickColor [Bright blue](#doc-brickcolor-23). ``` -------------------------------- ### Get BrickColor by ID - Lua Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/type/BrickColor.md This snippet demonstrates how to retrieve BrickColor information in Roblox Lua, by providing a BrickColor ID. It fetches the color name, RGB values, and Hex code. ```Lua function getBrickColorByID(id) -- This is a placeholder. In a real scenario, you would likely have a -- table or a way to look up colors by ID. For this example, we'll simulate. local colors = { [325] = {name = "Quill grey", rgb = "223, 223, 222", hex = "#DFDFDE"}, [327] = {name = "Crimson", rgb = "151, 0, 0", hex = "#970000"}, [328] = {name = "Mint", rgb = "177, 229, 166", hex = "#B1E5A6"}, [329] = {name = "Baby blue", rgb = "152, 194, 219", hex = "#98C2DB"}, [330] = {name = "Carnation pink", rgb = "255, 152, 220", hex = "#FF98DC"}, [331] = {name = "Persimmon", rgb = "255, 89, 89", hex = "#FF5959"}, [332] = {name = "Maroon", rgb = "117, 0, 0", hex = "#750000"}, [333] = {name = "Gold", rgb = "239, 184, 56", hex = "#EFB838"}, [334] = {name = "Daisy orange", rgb = "248, 217, 109", hex = "#F8D96D"}, [335] = {name = "Pearl", rgb = "231, 231, 236", hex = "#E7E7EC"}, [336] = {name = "Fog", rgb = "199, 212, 228", hex = "#C7D4E4"}, [337] = {name = "Salmon", rgb = "255, 148, 148", hex = "#FF9494"}, [338] = {name = "Terra Cotta", rgb = "190, 104, 98", hex = "#BE6862"}, [339] = {name = "Cocoa", rgb = "86, 36, 36", hex = "#562424"}, [340] = {name = "Wheat", rgb = "241, 231, 199", hex = "#F1E7C7"}, [341] = {name = "Buttermilk", rgb = "254, 243, 187", hex = "#FEF3BB"}, [342] = {name = "Mauve", rgb = "224, 178, 208", hex = "#E0B2D0"}, [343] = {name = "Sunrise", rgb = "212, 144, 189", hex = "#D490BD"}, [344] = {name = "Tawny", rgb = "150, 85, 85", hex = "#965555"} } return colors[id] end -- Example usage: local colorInfo = getBrickColorByID(333) if colorInfo then print("Color Name: " .. colorInfo.name) print("RGB: " .. colorInfo.rgb) print("Hex: " .. colorInfo.hex) else print("BrickColor ID not found.") end ``` -------------------------------- ### BrickColor Constructors Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/type/BrickColor.md Demonstrates various ways to create BrickColor objects in Roblox Lua. This includes instantiation using color number, name, RGB components, Color3 objects, palette index, random selection, and predefined static colors. ```lua -- BrickColor.new(value: number) -- BrickColor.new(name: string) -- BrickColor.new(r: number?, g: number?, b: number?) -- BrickColor.new(color: Color3) -- BrickColor.palette(index: number) -- BrickColor.random() -- BrickColor.White() -- BrickColor.Gray() -- BrickColor.DarkGray() -- BrickColor.Black() -- BrickColor.Red() -- BrickColor.Yellow() -- BrickColor.Green() -- BrickColor.Blue() ``` -------------------------------- ### HttpService PostAsync Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/HttpService.md Sends a POST request to a website. This is a shorthand for making POST requests. ```APIDOC ## POST /robloxapi/postasync ### Description Sends a POST request to a specified URL with provided data and returns the response body as a string. ### Method `POST` ### Endpoint `/robloxapi/postasync` ### Parameters #### Request Body - **url** (string) - Required - The URL to send the POST request to. - **body** (string) - Optional - The data to send in the request body. ### Request Example ```json { "url": "https://api.example.com/submit", "body": "name=example&value=test" } ``` ### Response #### Success Response (200) - **body** (string) - The response body from the server. #### Response Example ```json { "body": "{\"status\": \"received\"}" } ``` ``` -------------------------------- ### Lua Function Parameter Declaration with Types Source: https://github.com/robloxapi/doc/blob/master/man/typedec.md Shows how to declare parameters within a function type, pairing each parameter name with its corresponding type, separated by commas. Example uses 'Vector3' and 'int'. ```lua CFrame.new(position: Vector3, lookAt: Vector3) ``` -------------------------------- ### Lua: FindFirstChild Method with Boolean Argument Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/type/bool.md Demonstrates the use of the boolean 'recursive' argument in the FindFirstChild method. When true, it searches nested children; when false, it only searches direct children. This example requires an Instance object. ```lua local folder = Instance.new("Folder") local middle = Instance.new("Folder", folder) middle.Name = "Middle" local inner = Instance.new("Folder", middle) inner.Name = "Inner" print(folder:FindFirstChild("Inner", false)) --> nil print(folder:FindFirstChild("Inner", true)) --> Inner ``` -------------------------------- ### Copy Appearance Changes Between Parts (Lua) Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/Instance.md This Lua script demonstrates how to copy specific appearance properties (Color, Material, Reflectance, Transparency) from one Roblox Part to another when they change. It uses a dictionary to define which properties to track and connects to the `Changed` event of the original part. ```lua local appearance = { Color = true, Material = true, Reflectance = true, Transparency = true, } local original = Instance.new("Part", workspace) local copy = Instance.new("Part", workspace) original.Changed:Connect(function(property) if not appearance[property] then return end copy[property] = original[property] end) original.Position = Vector3.new(8, 0, 0) original.Color = BrickColor.Blue().Color ``` -------------------------------- ### Get Roblox Class Icon - Lua Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/StudioService.md Retrieves the explorer icon for a given Roblox class. It returns a table containing Image, ImageRectOffset, and ImageRectSize, which can be used to display the icon in ImageLabels or ImageButtons. An error is thrown if the class does not exist. ```lua local StudioService = game:GetService("StudioService") local TextService = game:GetService("TextService") local StarterGui = game:GetService("StarterGui") -- Get base size of icon, assuming all icons have the same size. local iconSize = StudioService:GetClassIcon("Instance").ImageRectSize local font = Enum.Font.SourceSans local fontSize = iconSize.Y local labelTextOffset = 2 -- Create label template. local labelTemplate = Instance.new("Frame") labelTemplate.Name = "ClassLabel" labelTemplate.BackgroundTransparency = 1 local iconTemplate = Instance.new("ImageLabel", labelTemplate) iconTemplate.Name = "IconLabel" iconTemplate.Size = UDim2.new(0, iconSize.X, 0, iconSize.Y) iconTemplate.BackgroundTransparency = 1 local textTemplate = Instance.new("TextLabel", labelTemplate) textTemplate.Name = "TextLabel" textTemplate.Position = UDim2.new(0, iconSize.X + labelTextOffset, 0, 0) textTemplate.TextXAlignment = Enum.TextXAlignment.Left textTemplate.BackgroundTransparency = 1 textTemplate.TextColor3 = Color3.new(1, 1, 1) -- Generate labels. local maxWidth = 0 local labels = {} local function createLabels(objects, depth) for i, object in pairs(objects) do -- Some objects are not friendly to being indexed. local ok, name = pcall(function() return object.Name end) if ok and object.ClassName ~= "" then local icon = StudioService:GetClassIcon(object.ClassName) local textSize = TextService:GetTextSize(name, fontSize, font, Vector2.new(0, 0)) local label = labelTemplate:Clone() label.Position = UDim2.new(0, depth * iconSize.X, 0, #labels * iconSize.Y) label.Size = UDim2.new(0, iconSize.X + textSize.X + labelTextOffset, 0, iconSize.Y) label.IconLabel.Image = icon.Image label.IconLabel.ImageRectOffset = icon.ImageRectOffset label.IconLabel.ImageRectSize = icon.ImageRectSize label.TextLabel.Text = name label.TextLabel.Size = UDim2.new(0, textSize.X, 0, iconSize.Y) local width = label.Position.X.Offset + label.Size.X.Offset if width > maxWidth then maxWidth = width end labels[#labels + 1] = label createLabels(object:GetChildren(), depth + 1) end end end createLabels(game:GetChildren(), 0) -- Generate GUI. local screen = Instance.new("ScreenGui") local container = Instance.new("ScrollingFrame", screen) local width = maxWidth + container.ScrollBarThickness container.Position = UDim2.new(0, 10, 0, 10) container.Size = UDim2.new(0, width, 1, -20) container.CanvasSize = UDim2.new(0, width, 0, #labels * iconSize.Y) container.BackgroundColor3 = Color3.new(0, 0, 0) container.BackgroundTransparency = 0.3 container.BorderSizePixel = 0 for _, label in pairs(labels) do label.Parent = container end screen.Parent = game.StarterGui ``` -------------------------------- ### Enforced Lerp Function Example Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/article/Intervals.md Presents a Lerp function with an enforced interval for the alpha parameter ([0, 1]). If alpha falls outside this range, the function throws an error, preventing invalid calculations and indicating a programming issue. ```Lua function Lerp(x, y, alpha) if alpha < 0 or alpha > 1 then error("alpha is out of bounds", 2) end return (1 - alpha) * x + alpha * y end ``` -------------------------------- ### Monitor Roblox Instance Hierarchy Events with Lua Source: https://context7.com/robloxapi/doc/llms.txt This Lua code snippet demonstrates how to monitor various instance hierarchy events in Roblox. It includes listening for player joining, character loading, object additions and removals in the workspace, and descendant events. This is useful for real-time game logic and debugging. ```lua -- Listen for new players joining game.Players.PlayerAdded:Connect(function(player) print(player.Name .. " joined the game") -- Wait for character to load player.CharacterAdded:Connect(function(character) print(player.Name .. "'s character loaded") -- Monitor character descendants character.DescendantAdded:Connect(function(descendant) if descendant:IsA("Tool") then print(player.Name .. " equipped:", descendant.Name) end end) end) end) -- Monitor workspace for new models workspace.ChildAdded:Connect(function(child) if child:IsA("Model") then print("New model added to workspace:", child.Name) -- Check if it has a humanoid (character or NPC) local humanoid = child:FindFirstChildOfClass("Humanoid") if humanoid then print("Humanoid found in", child.Name) humanoid.Died:Connect(function() print(child.Name .. " died") end) end end end) -- Track when objects are removed workspace.ChildRemoved:Connect(function(child) print("Object removed from workspace:", child.Name) end) -- Monitor all descendants being added anywhere in workspace workspace.DescendantAdded:Connect(function(descendant) if descendant:IsA("Explosion") then print("Explosion created at:", descendant.Position) elseif descendant:IsA("Fire") then print("Fire effect added") end end) -- Monitor before removal (DescendantRemoving fires BEFORE removal) workspace.DescendantRemoving:Connect(function(descendant) if descendant:IsA("Tool") and descendant.Parent then print("Tool being removed:", descendant.Name, "from", descendant.Parent.Name) end end) -- Clean up with Changed event local part = workspace:FindFirstChild("ImportantPart") if part then part.Changed:Connect(function(property) if property == "Parent" and not part.Parent then warn("ImportantPart was removed from workspace!") end end) end ``` -------------------------------- ### Clamped Lerp Function Example Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/article/Intervals.md Illustrates a Lerp function with a clamped interval for the alpha parameter ([0, 1]). Values outside this range are adjusted to the nearest bound (0 or 1), ensuring the result stays within the expected interpolation range. ```Lua function Lerp(x, y, alpha) if alpha < 0 then alpha = 0 elseif alpha > 1 then alpha = 1 end return (1 - alpha) * x + alpha * y end ``` -------------------------------- ### URL Encoding Strings in Lua Source: https://context7.com/robloxapi/doc/llms.txt Encodes strings to be safely included in URLs using Roblox's HttpService. This function correctly escapes special characters and spaces, making it suitable for building API request URLs. Examples include encoding a username and constructing a complete API endpoint with query parameters. ```lua local HttpService = game:GetService("HttpService") -- Encode special characters for URL local username = "Player #1" local encoded = HttpService:UrlEncode(username) print("Encoded:", encoded) -- "Player+%231" -- Build URL with parameters local function buildApiUrl(baseUrl, params) local url = baseUrl .. "?" local parts = {} for key, value in pairs(params) do table.insert(parts, key .. "=" .. HttpService:UrlEncode(tostring(value))) end return url .. table.concat(parts, "&") end local apiUrl = buildApiUrl("https://api.example.com/search", { query = "roblox games", limit = 10, category = "action & adventure" }) print("API URL:", apiUrl) -- https://api.example.com/search?query=roblox+games&limit=10&category=action+%26+adventure -- Use in actual HTTP request local searchQuery = "best weapons" local url = "https://api.example.com/items?q=" .. HttpService:UrlEncode(searchQuery) local response = HttpService:RequestAsync({ Url = url, Method = "GET" }) ``` -------------------------------- ### Lua Optional and Default Function Parameters Source: https://github.com/robloxapi/doc/blob/master/man/typedec.md Demonstrates the syntax for optional parameters (using '?') and parameters with default values (using '=') in Lua function type declarations. This covers flexibility in function signatures. ```lua table.insert(list: table, position: int?, value: Variant) FindFirstChild(name: string, recursive: bool = false) ``` -------------------------------- ### Children List Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/Instance.md Returns a list of the object's children. ```APIDOC ## Children Returns a list of the object's children. ### Method GET ### Endpoint /objects/{objectId}/children ### Description Retrieves a list of all direct children of the specified object. ``` -------------------------------- ### GetChildren Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/class/Instance.md Returns a list of the object's children. ```APIDOC ## GetChildren Returns a list of the object's children. ### Method GET ### Endpoint /objects/{objectId}/getChildren ### Description Retrieves a list containing all children of the specified object. ``` -------------------------------- ### Roblox API Constructors Source: https://github.com/robloxapi/doc/blob/master/man/writing.md Lists the constructor functions for Roblox API types. Function names include the type name (e.g., CFrame.new()). Return types can be omitted if they are of the current type. ```markdown # Constructors ## `CFrame.new()` ## `CFrame.new(position: Vector3)` ## `CFrame.new(position: Vector3, lookAt: Vector3)` ## `CFrame.new(x: number, y: number, z: number)` ## `CFrame.Angles(rx: number, ry: number, rz: number)` ``` -------------------------------- ### Lua Type Declaration with Qualifiers and Methods Source: https://github.com/robloxapi/doc/blob/master/man/typedec.md Demonstrates how to use dot notation for qualified names (e.g., 'math.huge') and colons for method declarations in Lua type declarations. This clarifies naming conventions for different types of entities. ```lua math.huge: number Instance:GetChildren(): Objects ``` -------------------------------- ### BrickColor Operators Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/type/BrickColor.md Explains how to compare BrickColor values. ```APIDOC # Operators ## `BrickColor == BrickColor` Determines whether BrickColor values are equal. ### Details A BrickColor is equal to another BrickColor if their Number fields are equal. ``` -------------------------------- ### Faces Constructor Source: https://github.com/robloxapi/doc/blob/master/src/doc/en/api/type/Faces.md Initializes a new Faces object. By default, all faces are false. You can provide a variable list of NormalId enum values to set corresponding faces to true. ```APIDOC ## `Faces.new(faces: ...Variant)` ### Description Initializes a new Faces object. All components are initialized to false by default. Accepts a variable list of arguments; only the first 6 are processed. When a `NormalId` value is provided, the corresponding component of Faces is set to true. Other values are ignored. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **faces** (...Variant) - Optional - A variable list of `NormalId` enum values to set corresponding faces to true. ### Request Example ```json { "faces": [ "Enum.NormalId.Right", "Enum.NormalId.Top" ] } ``` ### Response #### Success Response (200) - **Faces object**: The newly created Faces object with specified faces enabled. #### Response Example ```json { "Right": true, "Top": true, "Back": false, "Left": false, "Bottom": false, "Front": false } ``` ```