Syntax
instance:SetAttribute("LessonId", "movement")
local lessonId = instance:GetAttribute("LessonId")Examples
Inspect your character safely
LocalScript in StarterPlayerScripts. This is a one-time observation, not server-authoritative health logic. Timeouts and class checks avoid assuming every custom character has a standard rig.
local Players = game:GetService("Players")
local character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart", 10)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if root and root:IsA("BasePart") and humanoid then
print(root.Position, humanoid.Health)
endGive a part explicit configuration
Script in ServerScriptService. The boolean attribute is attached before parenting. A consumer should still check the type when reading configuration created by another script or an editor.
local marker = Instance.new("Part")
marker.Anchored = true
marker:SetAttribute("Enabled", true)
marker:SetAttribute("LessonId", "movement")
marker.Parent = workspace
local enabled = marker:GetAttribute("Enabled")
if typeof(enabled) == "boolean" and enabled then
print(marker:GetAttribute("LessonId"))
endBest practices
- Reacquire Humanoid and root references for each new character.
- Treat replicated attributes as public data.
- Check that a character is alive and close enough on the server before granting location-dependent actions.
At a glance
- Purpose
- Typed scripting and Roblox development
- File extension
- .luau
- Runs in
- Luau host; Roblox engine examples require Roblox Studio
- Usually used with
- Roblox APIs and Studio
Specifications & further reading
Related Luau documentation
Player lifecycle and character spawning
A Player can remain connected while its character is destroyed and replaced. Initialize player state once, and character state on every spawn. Connecting an event alone can miss objects that already exist when a script starts.Instances, properties and methods
Instances form the Roblox object tree. Properties describe an object, methods perform operations, and events report changes. Check the class before using class-specific properties; a child with the right name can still be the wrong kind of object.Server authority, validation and rate limits
A valid-looking remote call can still be an impossible game action. Validate both the shape of a request and whether the sender may perform it now. This example lets a nearby living player request a visual switch; it does not trust a client position, target Instance or reward.Script, LocalScript and ModuleScript placement
The same code can behave differently depending on where it runs. These lessons use server Scripts in ServerScriptService and LocalScripts in StarterPlayerScripts or StarterGui. A ModuleScript runs when required. Script RunContext also affects execution, so inspect it when a script appears silent.
A Player can remain connected while its character is destroyed and replaced. Initialize player state once, and character state on every spawn. Connecting an event alone can miss objects that already exist when a script starts.Instances, properties and methods
Instances form the Roblox object tree. Properties describe an object, methods perform operations, and events report changes. Check the class before using class-specific properties; a child with the right name can still be the wrong kind of object.Server authority, validation and rate limits
A valid-looking remote call can still be an impossible game action. Validate both the shape of a request and whether the sender may perform it now. This example lets a nearby living player request a visual switch; it does not trust a client position, target Instance or reward.Script, LocalScript and ModuleScript placement
The same code can behave differently depending on where it runs. These lessons use server Scripts in ServerScriptService and LocalScripts in StarterPlayerScripts or StarterGui. A ModuleScript runs when required. Script RunContext also affects execution, so inspect it when a script appears silent.