Codectionary / Developer documentation / Luau

Humanoid, HumanoidRootPart and attributes

Humanoid controls character behaviour such as health, while HumanoidRootPart gives a useful spatial reference. Attributes attach small named values to Instances. They are convenient for configuration and display, but client-side attributes are not proof that a player earned a reward.

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)
end

Give 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"))
end

Best 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