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.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation