### Full Tool Input Handling Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/tutorials/use-case-tutorials/input-and-camera/detect-user-input.md This comprehensive example demonstrates the complete setup for handling user input with a tool. It includes binding an action when the tool is equipped and unbinding it when unequipped, along with playing associated animations. ```lua local ContextActionService = game:GetService("ContextActionService") local tool = script.Parent local RELOAD_ACTION = "reloadWeapon" local function onAction(actionName, inputState, inputObject) if actionName == RELOAD_ACTION and inputState == Enum.UserInputState.Begin then tool.TextureId = "rbxassetid://6593020923" task.wait(2) tool.TextureId = "rbxassetid://92628145" end end local function toolEquipped() ContextActionService:BindAction(RELOAD_ACTION, onAction, true, Enum.KeyCode.R) tool.Handle.Equip:Play() end local function toolUnequipped() ContextActionService:UnbindAction(RELOAD_ACTION) end local function toolActivated() tool.Handle.Activate:Play() end tool.Equipped:Connect(toolEquipped) tool.Unequipped:Connect(toolUnequipped) tool.Activated:Connect(toolActivated) ``` -------------------------------- ### LocalScript Setup for CSS Comparison Examples Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/ui/styling/css-comparisons.md This script provides the necessary setup for testing CSS comparison examples in Roblox. It retrieves core services and instances required for styling. ```lua local CollectionService = game:GetService("CollectionService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet") local rule = coreSheet:FindFirstChildWhichIsA("StyleRule") local screenGui = script.Parent ``` -------------------------------- ### Example Output Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/luau/stacks.md This is the expected output when running the Stack Usage Example code. ```lua 10 5 20 1 ``` -------------------------------- ### Script Execution Warning Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/scripting/capabilities.md This example demonstrates the warning message displayed when a script fails to start due to missing execution control capabilities. ```text Cannot start server script 'Script' (lacking capability RunServerScript) ``` -------------------------------- ### Create Roblox Client Bundled Installer Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/support/creating-bundled-installers.md Use this command in the Command Prompt to create a bundled installer for the Roblox Client. Ensure you are in the directory of the Roblox Client executable. ```bash RobloxPlayerLauncher.exe -bundle ``` -------------------------------- ### Selection Algorithm Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/resources/coding-concept-algorithms.md Uses conditional statements such as if/then to determine an output. This example sets a stop light color based on time. ```lua if time == 0 then stopLightColor = red end ``` -------------------------------- ### Video Tutorial: Project Setup Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/art/accessories/creating/modeling-setup.md A video demonstrating the initial project setup process, including duplicating cage meshes, parenting, and renaming objects for your clothing accessory project. ```video ../../../assets/art/accessories/creating/Modeling_00.mp4 ``` -------------------------------- ### Example of a Complete Bundle Configuration Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/resources/feature-packages/bundles.md This example shows a full bundle definition using `RelativeTime` bundle type. It includes pricing via a developer product and multiple included items, each configured with Robux price and icon. Optional metadata for display name and description is also included. ```lua local starterBundle: Types.RelativeTimeBundle = { bundleType = Types.BundleType.RelativeTime, pricing = { priceType = CurrencyTypes.PriceType.Marketplace, devProductId = , }, includedItems = { [1] = { itemType = ItemTypes.ItemType.Robux, priceInRobux = 49, icon = , metadata = { caption = { text = "x1", color = Color3.fromRGB(236, 201, 74), }, }, }, [2] = { itemType = ItemTypes.ItemType.Robux, priceInRobux = 99, icon = , metadata = { caption = { text = "x1", color = Color3.fromRGB(236, 201, 74), }, }, }, [3] = { itemType = ItemTypes.ItemType.Robux, priceInRobux = 149, icon = , metadata = { caption = { text = "x1", color = Color3.fromRGB(236, 201, 74), }, }, }, }, singleUse = true, durationInSeconds = 900, includesOfflineTime = false, metadata = { displayName = "STARTER BUNDLE", description = "Save 75% and get a head start!", }, } ``` -------------------------------- ### Schedule Event with Multiple Start Times Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/resources/modules/event-sequencer.md Schedules an event to occur at multiple specific times. The OnStart function is executed at each specified time. This example demonstrates scheduling an event with two start times. ```lua Schema.OnRun = function() print("OnRun (Client)") Schema:schedule({ StartTimes = {5, 27.25}, OnStart = function(self) -- Initialize temporary heartbeat connection local tempConnection = RunService.Heartbeat:Connect(function() end) -- Inform framework of connection Schema:inform(tempConnection) end }) end ``` -------------------------------- ### Initialize Timer Variables and Timer Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/battle-royale-series/timers-and-events.md Set up variables for the Events folder, MatchStart, and MatchEnd events. Also, create a new timer instance. ```lua -- Module Scripts local moduleScripts = ServerStorage:WaitForChild("ModuleScripts") local playerManager = require(moduleScripts:WaitForChild("PlayerManager")) local gameSettings = require(moduleScripts:WaitForChild("GameSettings")) local timer = require(moduleScripts:WaitForChild("Timer")) -- Events local events = ServerStorage:WaitForChild("Events") local matchStart = events:WaitForChild("MatchStart") local matchEnd = events:WaitForChild("MatchEnd") --Creates timer local myTimer = timer.new() ``` -------------------------------- ### Get Player and Services Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/tutorials/use-case-tutorials/input-and-camera/control-the-users-camera.md Retrieves the Players service and the LocalPlayer object. This is a common setup for camera manipulation scripts. ```Lua local Players = game:GetService("Players") local player = Players.LocalPlayer ``` -------------------------------- ### Constant value example for server categorical signal Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/matchmaking/attributes-and-signals.md Provides a practical example of the constant value formula for a server categorical signal, checking if the game has not started. Returns 1 if the server attribute is true, 0 otherwise. ```lua local server_GameNotStarted = true if server_GameNotStarted = true then return 1 else return 0 end ``` -------------------------------- ### Serve a Rojo Project Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/projects/external-tools.md Start the Rojo server to enable live-syncing with Roblox Studio. This command should be run after building the project. ```bash rojo serve ``` -------------------------------- ### Initialize and Build a Rojo Project Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/projects/external-tools.md Create a new Rojo project structure and build the initial project files. This sets up the basic project for development. ```bash rojo init my-new-experience cd my-new-experience rojo build -o my-new-experience.rbxl ``` -------------------------------- ### Update GUI Status: Match Starting Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/battle-royale-series/creating-a-gui.md Updates the GUI status to 'Get ready!' after the intermission ends and before the match begins, within the GameManager script. ```lua while true do displayManager.updateStatus("Waiting for Players") repeat task.wait(gameSettings.intermissionDuration) until #Players:GetPlayers() >= gameSettings.minimumPlayers displayManager.updateStatus("Get ready!") task.wait(gameSettings.transitionTime) matchManager.prepareGame() matchEnd.Event:Wait() end ``` -------------------------------- ### Server Attribute Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/matchmaking/attributes-and-signals.md This example shows how to manage temporary server attributes. It includes initializing attributes for studio testing, retrieving an attribute's value, and updating an attribute. ```lua local MatchmakingService = game::GetService("MatchmakingService") local RunService = game:GetService("RunService") if RunService:IsStudio() then -- Sets up initial attributes and schema for testing MatchmakingService:InitializeServerAttributesForStudio( { Level = "Advanced", Elo = 123.456, TrainingMode = true }) end -- Retrieves the Level attribute local currentLevel, error = MatchmakingService:GetServerAttribute("Level") if error then print(error) else print("Current level: " .. currentLevel) end -- Updates the Level attribute value to Advanced local success, error = MatchmakingService:SetServerAttribute("Level", "Advanced") if not success then print("Failed to update server attribute [Level] to [Advanced] due to error: " .. error) else print("Successfully set [Level] to [Advanced]") end ``` -------------------------------- ### Comment Directives Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/luau/comments.md Use comment directives starting with '--!' to control Luau compiler features like type checking, native code generation, and linting. ```lua --!strict --!nonstrict --!nocheck --!native --!nolint --!optimize 0|1|2 ``` -------------------------------- ### Get Player Input and Declare Story Variable Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/tutorials/curriculums/coding/work-with-variables.md Captures player input for a favorite name and declares a local variable named 'story'. This is the initial setup for dynamic story content. ```lua -- ============================================= local name1 = storyMaker:GetInput("What is your favorite name?") local story -- ============================================= ``` -------------------------------- ### Initialize GUI Script Variables Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/battle-royale-series/creating-a-gui.md Sets up essential variables for a GUI script, including services, folders, values, and the parent TextLabel. Ensure ReplicatedStorage and the DisplayValues folder with the Status StringValue are set up before running. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local displayValues = ReplicatedStorage:WaitForChild("DisplayValues") local status = displayValues:WaitForChild("Status") local textLabel = script.Parent ``` -------------------------------- ### Notify All Clients of Laser Firing Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/tutorials/use-case-tutorials/scripting/intermediate-scripting/hit-detection-with-lasers.md In the playerFiredLaser function, after getting the tool handle, fire the LaserFired event to all clients. This includes the player who fired, the tool handle (start position), and the end position. ```Lua -- Notify all clients that a laser has been fired so they can display the laser local function playerFiredLaser(playerFired, endPosition) local toolHandle = getPlayerToolHandle(playerFired) if toolHandle then eventsFolder.LaserFired:FireAllClients(playerFired, toolHandle, endPosition) end end ``` -------------------------------- ### Tutorial Script for Player Guidance Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/build-it-play-it-mansion-of-wonder/adding-scripts.md This script manages the visual beam that guides players through tutorial goals and handles interaction events. It requires specific objects like 'PlayerTutorial' folder, 'TutorialManager', 'TutorialEndEvent', and 'TutorialBeam' to be present in ReplicatedStorage. ```lua local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local tutorialFolder = ReplicatedStorage:WaitForChild("PlayerTutorial") local TutorialManager = require(tutorialFolder:WaitForChild("TutorialManager")) local TutorialEndEvent = tutorialFolder:WaitForChild("TutorialEnd") local player = Players.LocalPlayer local goalParts = TutorialManager.getTutorialGoals() local playerBeam = nil local goalIndex = nil local function getTargetAttachment() local currentTarget = goalParts[goalIndex.Value] local interactionPart = currentTarget:FindFirstChild("InteractionPart") local attachment = interactionPart and interactionPart:FindFirstChildOfClass("Attachment") if not attachment then attachment = Instance.new("Attachment") attachment.Name = "BeamAttachment" attachment.Parent = currentTarget end return attachment end local function updateBeamTarget() playerBeam = player.Character.HumanoidRootPart:FindFirstChildOfClass("Beam") local targetBeamAttachment = getTargetAttachment() if targetBeamAttachment then playerBeam.Attachment1 = targetBeamAttachment else warn("Attachment not found in a goal. Check that goals have attachments or they're included under the InteractionPart") end end local function setupGoals() for _, part in goalParts do local interactionPart = part:FindFirstChild("InteractionPart") local proximityPrompt = interactionPart and interactionPart:FindFirstChild("ProximityPrompt") if proximityPrompt then proximityPrompt.Triggered:Connect(function(player) proximityPrompt.Enabled = false TutorialManager.nextGoal(player, goalParts) TutorialManager.interactGoal(player) end) else warn("Proximity prompt not included in goal. Add one to each goal part under the InteractionPart") end end end local function createBeamForCharacter(character) local humanoidRootPart = character:WaitForChild("HumanoidRootPart") local playerBeamAttachment = Instance.new("Attachment") local beamTemplate = tutorialFolder:WaitForChild("TutorialBeam") if not beamTemplate then warn("Tutorial Beam not found in ReplicatedStorage") end playerBeamAttachment.Name = "BeamAttachment" playerBeamAttachment.Parent = humanoidRootPart local targetBeamAttachment = getTargetAttachment() playerBeam = beamTemplate:Clone() playerBeam.Attachment0 = playerBeamAttachment playerBeam.Attachment1 = targetBeamAttachment playerBeam.Enabled = true playerBeam.Parent = humanoidRootPart end local function setupPlayer() setupGoals() TutorialManager.setupPlayerProgress(player) goalIndex = player:WaitForChild("GoalProgress") player.CharacterAdded:Connect(createBeamForCharacter) if player.Character then createBeamForCharacter(player.Character) end end setupPlayer() goalIndex.Changed:Connect(updateBeamTarget) ``` -------------------------------- ### Get Player's Tool Handle on Server Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/tutorials/use-case-tutorials/scripting/intermediate-scripting/hit-detection-with-lasers.md A utility function to find the handle of the weapon tool currently held by a player. This is used to determine the laser's starting position on the server. ```Lua local LASER_DAMAGE = 10 -- Find the handle of the tool the player is holding local function getPlayerToolHandle(player) local weapon = player.Character:FindFirstChildOfClass("Tool") if weapon then return weapon:FindFirstChild("Handle") end end ``` -------------------------------- ### DragDetector - Event Signals Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/ui/3D-drag-detectors.md Connect to DragStart, DragContinue, and DragEnd signals to manage visual feedback or game logic during dragging. This example enables a Highlight instance when dragging starts and disables it when dragging ends. ```lua local dragDetector = script.Parent.DragDetector local highlight = Instance.new("Highlight") highlight.Enabled = false highlight.Parent = script.Parent dragDetector.DragStart:Connect(function() highlight.Enabled = true end) dragDetector.DragContinue:Connect(function() end) dragDetector.DragEnd:Connect(function() highlight.Enabled = false end) ``` -------------------------------- ### Initialize Player Manager Services and Modules Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/battle-royale-series/ending-matches.md Sets up necessary services like Players, ServerStorage, and ReplicatedStorage, and requires modules like GameSettings. It also defines the MatchEnd event from ReplicatedStorage. ```lua local PlayerManager = {} -- Services local Players = game:GetService("Players") local ServerStorage = game:GetService("ServerStorage") local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Modules local moduleScripts = ServerStorage:WaitForChild("ModuleScripts") local gameSettings = require(moduleScripts:WaitForChild("GameSettings")) -- Events local events = ServerStorage:WaitForChild("Events") local matchEnd = events:WaitForChild("MatchEnd") ``` -------------------------------- ### Leaderboard Setup Script Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/tutorials/fundamentals/coding-3/give-points.md This script sets up a basic leaderboard for players, creating a 'leaderstats' folder and an 'Points' IntValue for each player upon joining. It's essential for tracking scores in the project. ```lua --In ServerScriptService, create a script named PlayerSetup with the contents below. local Players = game:GetService("Players") local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player -- Example of an IntValue local points = Instance.new("IntValue") points.Name = "Points" points.Value = 0 points.Parent = leaderstats end -- Run onPlayerJoin when the PlayerAdded event fires Players.PlayerAdded:Connect(onPlayerJoin) ``` -------------------------------- ### Setup Blaster Selection Button Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/tutorials/curriculums/user-interface-design/implement-designs-in-studio.md This script confirms the player's blaster selection with the server. When a player presses the select button, it gets the blaster name and sends it to the server to equip the correct blaster type. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local GuiAttribute = require(ReplicatedStorage.GuiAttribute) local blasterSelectedEvent = ReplicatedStorage.Instances.BlasterSelectedEvent local function setupSelectButton(gui: ScreenGui, blasterButtons: { ImageButton }) gui.Frame.SelectButton.Activated:Connect(function() -- During button generation, we set the name of the button to correspond to its associated blaster type local blasterName = blasterButtons[gui:GetAttribute(GuiAttribute.selectedIndex)].Name blasterSelectedEvent:FireServer(blasterName) end) end return setupSelectButton ``` -------------------------------- ### Getting a Range of Keys from a Sorted Map Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/cloud-services/memory-stores/sorted-map.md Retrieves a range of items from a sorted map. You can specify the sort direction, the maximum number of items to retrieve, and optional lower and upper bounds for keys and sort keys. The example retrieves up to 20 items with keys between "10" and "50" and sort keys between 100 and 500. ```lua local MemoryStoreService = game:GetService("MemoryStoreService") local sortedMap = MemoryStoreService:GetSortedMap("SortedMap1") local lowerBound = {} lowerBound["key"] = "10" lowerBound["sortKey"] = 100 local upperBound = {} upperBound["key"] = "50" upperBound["sortKey"] = 500 -- Get up to 20 items starting from the beginning local getSuccess, items = pcall(function() return sortedMap:GetRangeAsync( Enum.SortDirection.Ascending, 20, lowerBound, upperBound) end) if getSuccess then for _, item in items do print(item.key) print(item.sortKey) end end ``` -------------------------------- ### Server Schema OnSetup Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/resources/modules/event-sequencer.md Initializes server-side assets and sets up event connections in OnSetup. Connects to EventSequencer. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local EventSequencer = require(ReplicatedStorage:WaitForChild("EventSequencer")) local Schema = EventSequencer.createSchema() local serverEnvironment local partColorConnection local changePartColorEvent = script.Parent.Events.ChangePartColor Schema.OnSetup = function(timePositionObject) print("OnSetup (Server)") -- Access scene environment; does not apply to Inline Mode serverEnvironment = EventSequencer.getCurrentSceneEnvironment() partColorConnection = changePartColorEvent.OnServerEvent:Connect(function(player, changedPart, newColor) serverEnvironment.changedPart.Color = newColor end) print("Current time is:", timePositionObject.Value) end ``` -------------------------------- ### Install Rojo Plugin for Roblox Studio Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/projects/external-tools.md Install the Rojo plugin directly within Roblox Studio. This command is run after Rojo has been installed via Foreman. ```bash rojo plugin install ``` -------------------------------- ### Initialize GameSettings Module Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/battle-royale-series/coding-the-game-loop.md Create a module script named GameSettings and rename the module table to match the script name. This is the initial setup before adding variables. ```lua local GameSettings = {} return GameSettings ``` -------------------------------- ### Initialize Sell Platform Script Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/adventure-game-series/selling-items.md This snippet initializes the script by getting a reference to the parent part, which acts as the sell platform. ```Lua -- Sells all a player's items and gives them gold local sellPart = script.Parent ``` -------------------------------- ### HTML Structure for SCSS Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/ui/styling/css-comparisons.md Provides the HTML structure corresponding to the SCSS styling example. ```html ``` -------------------------------- ### Initialize Buy Button and Click Detector Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/adventure-game-series/buying-upgrades.md Sets up local variables for the button part and its associated ClickDetector. This is the initial setup for handling player clicks on a shop item. ```Lua -- Lets players click a button to buy an upgrade that increases Spaces local buyButton = script.Parent local clickDetector = buyButton.ClickDetector ``` -------------------------------- ### CSS Hover Pseudo-class Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/ui/styling/css-comparisons.md This is a CSS example demonstrating how to change the opacity of an image when a user hovers over it. ```text img:hover { opacity: 0.5; } ``` -------------------------------- ### Iteration Algorithm Example Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/resources/coding-concept-algorithms.md Repeats parts of the code as necessary, such as in for loops or multiplication. This example counts down time. ```lua for countDown = 10, 1, -1 do time -= 1 task.wait(1) end ``` -------------------------------- ### Create Roblox Studio Bundled Installer Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/education/support/creating-bundled-installers.md Use this command in the Command Prompt to create a bundled installer for Roblox Studio. Ensure you are in the directory of the Roblox Studio executable. ```bash RobloxStudioLauncherBeta.exe -bundle ``` -------------------------------- ### Warning Alert Example Source: https://github.com/largegames/creator-docs/blob/main/STYLE.md Example of a warning alert. Use this to inform users about beta features or potential issues. ```markdown This is a beta feature and is subject to change in future releases. ``` -------------------------------- ### Example Script for In-Experience Asset Creation Source: https://github.com/largegames/creator-docs/blob/main/content/en-us/projects/assets/in-experience-asset-creation.md This server-side script demonstrates how to use AssetService:PromptCreateAssetAsync() to prompt users to save a model as an asset. It handles the success or failure of the asset upload and prints the result. ```lua -- Define the AssetService variable local AssetService = game:GetService("AssetService") -- Set up PromptCreateAssetAsync() for prompting the submission dialog local function CreateAsset(player, instance) local complete, result, assetId = pcall(function() return AssetService:PromptCreateAssetAsync(player, instance, Enum.AssetType.Model) end) if complete then if result == Enum.PromptCreateAssetResult.Success then print("successfully uploaded, AssetId:", assetId) else print("Received result", result) end else print("error") print(result) end end -- Car painting logic omitted -- Add an event handler local function onUserPublish(player, promptObject) -- User saves the car instance with the experience's default color if promptObject.Name == "car" then CreateAsset(player, car) elseif promptObject.Name == "CarPaintYellow" or promptObject.Name == "CarPaintBlue" or promptObject.Name == "CarPaintBlack" or promptObject.Name == "CarPaintRed" then PaintCarColor(promptObject.Name) end end PublishEvent:OnServerEvent:Connect(onUserPublish) ```