学习
引擎类
Humanoid

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处


概要
方法
AddAccessory(accessory: Instance):()
AddCustomStatus(status: string):boolean
已弃用
AddStatus(status: Enum.Status):boolean
已弃用
ApplyDescription(humanoidDescription: HumanoidDescription,assetTypeVerification: Enum.AssetTypeVerification):()
已弃用
ApplyDescriptionAsync(humanoidDescription: HumanoidDescription,assetTypeVerification: Enum.AssetTypeVerification):()
ApplyDescriptionReset(humanoidDescription: HumanoidDescription,assetTypeVerification: Enum.AssetTypeVerification):()
已弃用
ApplyDescriptionResetAsync(humanoidDescription: HumanoidDescription,assetTypeVerification: Enum.AssetTypeVerification):()
GetStatuses():{any}
已弃用
HasCustomStatus(status: string):boolean
已弃用
HasStatus(status: Enum.Status):boolean
已弃用
LoadAnimation(animation: Animation):AnimationTrack
已弃用
loadAnimation(animation: Animation):AnimationTrack
已弃用
Move(moveDirection: Vector3,relativeToCamera: boolean):()
MoveTo(location: Vector3,part: Instance):()
PlayEmote(emoteName: string):boolean
已弃用
RemoveCustomStatus(status: string):boolean
已弃用
RemoveStatus(status: Enum.Status):boolean
已弃用
TakeDamage(amount: number):()
takeDamage(amount: number):()
已弃用
继承成员
代码示例
行走相机摇动效果
local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- 角色在行走吗?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- 缩小 CameraOffset,以便它回到正常位置。
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)

API 参考
属性
AutoJumpEnabled
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.AutoJumpEnabled:boolean
代码示例
自动跳跃切换
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- 更新按钮文本
if player.AutoJumpEnabled then
button.Text = "自动跳跃已开启"
else
button.Text = "自动跳跃已关闭"
end
-- 如果玩家有角色,反映该属性
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- 切换自动跳跃
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- 更新其他所有内容
update()
end
button.Activated:Connect(onActivated)
update()

AutomaticScalingEnabled
读取并联
功能: AvatarAppearance
Humanoid.AutomaticScalingEnabled:boolean

AutoRotate
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.AutoRotate:boolean
代码示例
自动旋转按钮
local button = script.Parent
local enabled = true
local ON_COLOR = BrickColor.Green()
local OFF_COLOR = BrickColor.Red()
local function touchButton(humanoid)
if enabled then
enabled = false
button.BrickColor = OFF_COLOR
if humanoid.AutoRotate then
print(humanoid:GetFullName() .. " 不能再自动旋转!")
humanoid.AutoRotate = false
else
print(humanoid:GetFullName() .. " 现在可以自动旋转!")
humanoid.AutoRotate = true
end
task.wait(1)
button.BrickColor = ON_COLOR
enabled = true
end
end
local function onTouched(hit)
local char = hit:FindFirstAncestorWhichIsA("Model")
if char then
local humanoid = char:FindFirstChildOfClass("Humanoid")
if humanoid then
touchButton(humanoid)
end
end
end
button.Touched:Connect(onTouched)
button.BrickColor = ON_COLOR

BreakJointsOnDeath
读取并联
功能: AvatarBehavior
Humanoid.BreakJointsOnDeath:boolean

CameraOffset
读取并联
功能: AvatarBehavior
Humanoid.CameraOffset:Vector3
代码示例
行走相机摇动效果
local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- 角色在行走吗?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- 缩小 CameraOffset,以便它回到正常位置。
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)

CollisionType
已弃用

DisplayDistanceType
读取并联
功能: AvatarAppearance
Humanoid.DisplayDistanceType:Enum.HumanoidDisplayDistanceType
代码示例
显示类人的健康和名称
local humanoid = script.Parent
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
humanoid.HealthDisplayDistance = 0
humanoid.NameDisplayDistance = 100

DisplayName
读取并联
功能: AvatarAppearance
Humanoid.DisplayName:string

EvaluateStateMachine
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.EvaluateStateMachine:boolean

FloorMaterial
只读
未复制
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.FloorMaterial:Enum.Material

Health
未复制
读取并联
功能: AvatarBehavior
Humanoid.Health:number

HealthDisplayDistance
读取并联
功能: AvatarAppearance
Humanoid.HealthDisplayDistance:number

HealthDisplayType
读取并联
功能: AvatarAppearance
Humanoid.HealthDisplayType:Enum.HumanoidHealthDisplayType

HipHeight
读取并联
功能: AvatarAppearance
模拟访问权限
Humanoid.HipHeight:number

Jump
未复制
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.Jump:boolean

JumpHeight
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.JumpHeight:number

JumpPower
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.JumpPower:number

LeftLeg
已弃用

MaxHealth
读取并联
功能: AvatarBehavior
Humanoid.MaxHealth:number

maxHealth
已弃用

MaxSlopeAngle
读取并联
功能: AvatarBehavior
Humanoid.MaxSlopeAngle:number
代码示例
限制人形生物可以攀爬的坡度
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char:FindFirstChild("Humanoid")
h.MaxSlopeAngle = 30

MoveDirection
只读
未复制
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.MoveDirection:Vector3
代码示例
行走相机摇动效果
local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- 角色在行走吗?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- 缩小 CameraOffset,以便它回到正常位置。
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)

NameDisplayDistance
读取并联
功能: AvatarAppearance
Humanoid.NameDisplayDistance:number

NameOcclusion
读取并联
功能: AvatarAppearance
Humanoid.NameOcclusion:Enum.NameOcclusion
代码示例
阻碍玩家名字
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.NamOcclusion = Enum.NameOcclusion.OccludeAll
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

PlatformStand
读取并联
功能: AvatarBehavior
Humanoid.PlatformStand:boolean

RequiresNeck
读取并联
功能: AvatarBehavior
Humanoid.RequiresNeck:boolean

RightLeg
已弃用

RigType
读取并联
功能: AvatarAppearance
Humanoid.RigType:Enum.HumanoidRigType

RootPart
只读
未复制
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.RootPart:BasePart

SeatPart
只读
未复制
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.SeatPart:BasePart

Sit
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.Sit:boolean

TargetPoint
读取并联
功能: AvatarBehavior
Humanoid.TargetPoint:Vector3

Torso
已弃用

UseJumpPower
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.UseJumpPower:boolean

WalkSpeed
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.WalkSpeed:number

WalkToPart
读取并联
功能: AvatarBehavior
Humanoid.WalkToPart:BasePart

WalkToPoint
读取并联
功能: AvatarBehavior
模拟访问权限
Humanoid.WalkToPoint:Vector3

方法
AddAccessory
功能: AvatarAppearance
Humanoid:AddAccessory(accessory:Instance):()
参数
accessory:Instance
返回
()
代码示例
[Humanoid] 添加配件示例
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local clockworksShades = Instance.new("Accessory")
clockworksShades.Name = "ClockworksShades"
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1, 1.6, 1)
handle.Parent = clockworksShades
local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "FaceFrontAttachment"
faceFrontAttachment.Position = Vector3.new(0, -0.24, -0.45)
faceFrontAttachment.Parent = handle
local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1, 1.3, 1)
mesh.MeshId = "rbxassetid://1577360"
mesh.TextureId = "rbxassetid://1577349"
mesh.Parent = handle
humanoid:AddAccessory(clockworksShades)

AddCustomStatus
已弃用

AddStatus
已弃用

ApplyDescription
已弃用

ApplyDescriptionAsync
暂停
功能: AvatarAppearance
Humanoid:ApplyDescriptionAsync(
humanoidDescription:HumanoidDescription, assetTypeVerification:Enum.AssetTypeVerification
):()
参数
humanoidDescription:HumanoidDescription
assetTypeVerification:Enum.AssetTypeVerification
默认值:"Default"
返回
()

ApplyDescriptionReset
已弃用

ApplyDescriptionResetAsync
暂停
功能: AvatarAppearance
Humanoid:ApplyDescriptionResetAsync(
humanoidDescription:HumanoidDescription, assetTypeVerification:Enum.AssetTypeVerification
):()
参数
humanoidDescription:HumanoidDescription
assetTypeVerification:Enum.AssetTypeVerification
默认值:"Default"
返回
()

BuildRigFromAttachments
功能: AvatarBehavior
Humanoid:BuildRigFromAttachments():()
返回
()
代码示例
Lua 版的 BuildRigFromAttachments
local function createJoint(jointName, att0, att1)
local partForJoint = att1.Parent
while partForJoint and not partForJoint:IsA("BasePart") do
partForJoint = partForJoint.Parent
end
local oldJoint = partForJoint:FindFirstChild(jointName)
if oldJoint and oldJoint:IsA("AnimationConstraint") then
oldJoint.Attachment0 = att0
oldJoint.Attachment1 = att1
oldJoint.Parent = partForJoint
else
local ac = Instance.new("AnimationConstraint")
ac.Name = jointName
ac.IsKinematic = true
ac.Attachment0 = att0
ac.Attachment1 = att1
ac.Parent = partForJoint
end
end
local function collectRigAttachments(part)
local rigAttachments = {}
for _, child in pairs(part:GetChildren()) do
if child:IsA("Attachment") and child.Name:find("RigAttachment$") then
rigAttachments[child.Name] = child
end
end
-- 骨骼可能包含更深层的 RigAttachments,覆盖部件级别的
-- 部件(R15+ 扩展骨骼)。
for _, child in pairs(part:GetChildren()) do
if child:IsA("Bone") then
for _, descendant in pairs(child:GetDescendants()) do
if descendant:IsA("Attachment") and descendant.Name:find("RigAttachment$") then
rigAttachments[descendant.Name] = descendant
end
end
end
end
return rigAttachments
end
local function buildJointsFromAttachments(part, characterParts, visitedParts)
if not part or visitedParts[part] then
return
end
visitedParts[part] = true
local rigAttachments = collectRigAttachments(part)
for attachmentName, attachment in pairs(rigAttachments) do
local jointName = attachmentName:sub(1, #attachmentName - #"RigAttachment")
if not part:FindFirstChild(jointName) then
for _, characterPart in pairs(characterParts) do
if not visitedParts[characterPart] then
local matchingAttachment = characterPart:FindFirstChild(attachmentName)
if matchingAttachment and matchingAttachment:IsA("Attachment") then
createJoint(jointName, attachment, matchingAttachment)
buildJointsFromAttachments(characterPart, characterParts, visitedParts)
break
end
end
end
end
end
end
local function buildRigFromAttachments(humanoid)
local rootPart = humanoid.RootPart
assert(rootPart, "Humanoid 没有 HumanoidRootPart.")
local characterParts = {}
for _, descendant in ipairs(humanoid.Parent:GetDescendants()) do
if descendant:IsA("BasePart") then
table.insert(characterParts, descendant)
end
end
local visitedParts = {}
buildJointsFromAttachments(rootPart, characterParts, visitedParts)
end
local humanoid = script.Parent:WaitForChild("Humanoid")
buildRigFromAttachments(humanoid)
R15 包导入器
local AssetService = game:GetService("AssetService")
local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")
local PACKAGE_ASSET_ID = 193700907 -- 电路断路器
local function addAttachment(part, name, position, orientation)
local attachment = Instance.new("Attachment")
attachment.Name = name
attachment.Parent = part
if position then
attachment.Position = position
end
if orientation then
attachment.Orientation = orientation
end
return attachment
end
local function createBaseCharacter()
local character = Instance.new("Model")
local humanoid = Instance.new("Humanoid")
humanoid.Parent = character
local rootPart = Instance.new("Part")
rootPart.Name = "HumanoidRootPart"
rootPart.Size = Vector3.new(2, 2, 1)
rootPart.Transparency = 1
rootPart.Parent = character
addAttachment(rootPart, "RootRigAttachment")
local head = Instance.new("Part")
head.Name = "Head"
head.Size = Vector3.new(2, 1, 1)
head.Parent = character
local headMesh = Instance.new("SpecialMesh")
headMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
headMesh.MeshType = Enum.MeshType.Head
headMesh.Parent = head
local face = Instance.new("Decal")
face.Name = "face"
face.Texture = "rbxasset://textures/face.png"
face.Parent = head
addAttachment(head, "FaceCenterAttachment")
addAttachment(head, "FaceFrontAttachment", Vector3.new(0, 0, -0.6))
addAttachment(head, "HairAttachment", Vector3.new(0, 0.6, 0))
addAttachment(head, "HatAttachment", Vector3.new(0, 0.6, 0))
addAttachment(head, "NeckRigAttachment", Vector3.new(0, -0.5, 0))
return character, humanoid
end
local function createR15Package(packageAssetId)
local packageAssetInfo = MarketplaceService:GetProductInfoAsync(packageAssetId)
local character, humanoid = createBaseCharacter()
character.Name = packageAssetInfo.Name
local assetIds = AssetService:GetAssetIdsForPackageAsync(packageAssetId)
for _, assetId in pairs(assetIds) do
local limb = InsertService:LoadAsset(assetId)
local r15 = limb:FindFirstChild("R15")
if r15 then
for _, part in pairs(r15:GetChildren()) do
part.Parent = character
end
else
for _, child in pairs(limb:GetChildren()) do
child.Parent = character
end
end
end
humanoid:BuildRigFromAttachments()
return character
end
local r15Package = createR15Package(PACKAGE_ASSET_ID)
r15Package.Parent = workspace

ChangeState
功能: AvatarBehavior
模拟访问权限
Humanoid:ChangeState(state:Enum.HumanoidStateType):()
参数
默认值:"None"
返回
()
代码示例
双重跳跃
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local doubleJumpEnabled = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not doubleJumpEnabled then
task.wait(0.2)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
doubleJumpEnabled = true
end
end
elseif newState == Enum.HumanoidStateType.Landed then
doubleJumpEnabled = false
end
end)
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.Space then
if doubleJumpEnabled then
if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.spawn(function()
doubleJumpEnabled = false
end)
end
end
end
end)

EquipTool
功能: AvatarBehavior
Humanoid:EquipTool(tool:Instance):()
参数
返回
()

GetAccessories
功能: AvatarAppearance
Humanoid:GetAccessories():{any}
返回
代码示例
移除加载后的配件
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- 此时所有配件已经加载完毕
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("正在销毁 %d 个配件,为 %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- 确保在玩家离开后断开与玩家的连接
-- 以允许玩家被垃圾回收
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)

GetAppliedDescription
功能: AvatarAppearance
Humanoid:GetAppliedDescription():HumanoidDescription

GetBodyPartR15
功能: AvatarBehavior
Humanoid:GetBodyPartR15(part:Instance):Enum.BodyPartR15
参数

GetLimb
功能: AvatarBehavior
Humanoid:GetLimb(part:Instance):Enum.Limb
参数
返回
代码示例
获取一个 humanoid 的肢体
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
for _, child in pairs(character:GetChildren()) do
local limb = humanoid:GetLimb(child)
if limb ~= Enum.Limb.Unknown then
print(child.Name .. " 是肢体 " .. limb.Name .. " 的一部分")
end
end

GetMoveVelocity
功能: AvatarBehavior
Humanoid:GetMoveVelocity():Vector3
返回

GetPlayingAnimationTracks
已弃用

GetRelativeVelocityAtFloor
功能: AvatarBehavior
模拟访问权限
Humanoid:GetRelativeVelocityAtFloor():Vector3
返回

GetState
写入并联
功能: AvatarBehavior
模拟访问权限
Humanoid:GetState():Enum.HumanoidStateType
代码示例
双重跳跃
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local doubleJumpEnabled = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not doubleJumpEnabled then
task.wait(0.2)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
doubleJumpEnabled = true
end
end
elseif newState == Enum.HumanoidStateType.Landed then
doubleJumpEnabled = false
end
end)
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.Space then
if doubleJumpEnabled then
if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.spawn(function()
doubleJumpEnabled = false
end)
end
end
end
end)

GetStateEnabled
写入并联
功能: AvatarBehavior
模拟访问权限
Humanoid:GetStateEnabled(state:Enum.HumanoidStateType):boolean
返回
代码示例
设置和获取 Humanoid 状态
local humanoid = script.Parent:WaitForChild("Humanoid")
-- 设置状态
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
-- 获取状态
print(humanoid:GetStateEnabled(Enum.HumanoidStateType.Jumping)) -- false

GetStatuses
已弃用

HasCustomStatus
已弃用

HasStatus
已弃用

LoadAnimation
已弃用

loadAnimation
已弃用

Move
功能: AvatarBehavior
模拟访问权限
Humanoid:Move(
moveDirection:Vector3, relativeToCamera:boolean
):()
参数
moveDirection:Vector3
relativeToCamera:boolean
默认值:false
返回
()
代码示例
移动幽灵角色向前
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
RunService:BindToRenderStep("move", Enum.RenderPriority.Character.Value + 1, function()
if player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid:Move(Vector3.new(0, 0, -1), true) -- 向前移动
end
end
end)

MoveTo
功能: AvatarBehavior
模拟访问权限
Humanoid:MoveTo(
location:Vector3, part:Instance
):()
参数
location:Vector3
默认值:"nil"
返回
()
代码示例
人形移动到目标点(无超时)
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- 监听 humanoid 达到目标
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- 开始行走
humanoid:MoveTo(targetPoint)
-- 在新线程中执行,以免使函数阻塞
task.spawn(function()
while not targetReached do
-- humanoid 仍然存在吗?
if not (humanoid and humanoid.Parent) then
break
end
-- 目标是否发生了变化?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- 刷新超时
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- 如果连接仍然连接,则断开连接
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "目标已到达!") or "未能到达目标!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)

PlayEmote
已弃用

PlayEmoteAsync
暂停
功能: AvatarBehavior
Humanoid:PlayEmoteAsync(emoteName:string):boolean
参数
emoteName:string
返回

RemoveAccessories
功能: AvatarAppearance
Humanoid:RemoveAccessories():()
返回
()
代码示例
移除加载后的配件
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- 此时所有配件已经加载完毕
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("正在销毁 %d 个配件,为 %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- 确保在玩家离开后断开与玩家的连接
-- 以允许玩家被垃圾回收
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)

RemoveCustomStatus
已弃用

RemoveStatus
已弃用

ReplaceBodyPartR15
功能: AvatarAppearance
Humanoid:ReplaceBodyPartR15(
bodyPart:Enum.BodyPartR15, part:BasePart
参数
返回

SetStateEnabled
功能: AvatarBehavior
模拟访问权限
Humanoid:SetStateEnabled(
):()
参数
enabled:boolean
返回
()
代码示例
跳跃冷却
local character = script.Parent
local JUMP_DEBOUNCE = 1
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
task.wait(JUMP_DEBOUNCE)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)

TakeDamage
功能: AvatarBehavior
Humanoid:TakeDamage(amount:number):()
参数
amount:number
返回
()
代码示例
对人形敌人造成伤害
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- 对人形敌人造成 99 点伤害
humanoid:TakeDamage(99)

takeDamage
已弃用

UnequipTools
功能: AvatarBehavior
Humanoid:UnequipTools():()
返回
()

活动
AnimationPlayed
已弃用

ApplyDescriptionFinished
功能: AvatarAppearance
Humanoid.ApplyDescriptionFinished(description:HumanoidDescription):RBXScriptSignal
参数

Climbing
功能: AvatarBehavior
Humanoid.Climbing(speed:number):RBXScriptSignal
参数
speed:number
代码示例
人形.攀爬
local Players = game:GetService("Players")
local function onCharacterClimbing(character, speed)
print(character.Name, "正在以", speed, "方块 / 秒的速度攀爬.")
end
local function onCharacterAdded(character)
character.Humanoid.Climbing:Connect(function(speed)
onCharacterClimbing(character, speed)
end)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

CustomStatusAdded
已弃用

CustomStatusRemoved
已弃用

Died
功能: AvatarBehavior
Humanoid.Died():RBXScriptSignal
代码示例
人形.死亡
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
print(player.Name, "已经死亡!")
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

FallingDown
功能: AvatarBehavior
Humanoid.FallingDown(active:boolean):RBXScriptSignal
参数
active:boolean

FreeFalling
功能: AvatarBehavior
Humanoid.FreeFalling(active:boolean):RBXScriptSignal
参数
active:boolean

GettingUp
功能: AvatarBehavior
Humanoid.GettingUp(active:boolean):RBXScriptSignal
参数
active:boolean

HealthChanged
功能: AvatarBehavior
Humanoid.HealthChanged(health:number):RBXScriptSignal
参数
health:number
代码示例
人形.HealthChanged
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local currentHealth = humanoid.Health
local function onHealthChanged(health)
local change = math.abs(currentHealth - health)
print("人形的健康状态", (currentHealth > health and "减少了" or "增加了"), change)
currentHealth = health
end
humanoid.HealthChanged:Connect(onHealthChanged)
end
player.CharacterAdded:Connect(onCharacterAdded)
生命值条
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- 将脚本粘贴到一个 LocalScript 中,该脚本
-- 是一个在框架内的框架的父对象
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- 黑色
-- 当人形的生命值发生变化时调用此函数
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- 改变内框的大小
frame.Size = UDim2.new(percent, 0, 1, 0)
-- 改变生命值条的颜色
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- 黑色
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- 黄色
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- 绿色
end
end
-- 当角色生成时调用此函数
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- 模式:一次更新,现在以及每次生命值变化时
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- 连接我们的生成监听器;如果已经生成,则调用它
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end

Jumping
功能: AvatarBehavior
Humanoid.Jumping(active:boolean):RBXScriptSignal
参数
active:boolean

MoveToFinished
功能: AvatarBehavior
Humanoid.MoveToFinished(reached:boolean):RBXScriptSignal
参数
reached:boolean
代码示例
人形移动到目标点(无超时)
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- 监听 humanoid 达到目标
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- 开始行走
humanoid:MoveTo(targetPoint)
-- 在新线程中执行,以免使函数阻塞
task.spawn(function()
while not targetReached do
-- humanoid 仍然存在吗?
if not (humanoid and humanoid.Parent) then
break
end
-- 目标是否发生了变化?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- 刷新超时
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- 如果连接仍然连接,则断开连接
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "目标已到达!") or "未能到达目标!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)

PlatformStanding
功能: AvatarBehavior
Humanoid.PlatformStanding(active:boolean):RBXScriptSignal
参数
active:boolean

Ragdoll
功能: AvatarBehavior
Humanoid.Ragdoll(active:boolean):RBXScriptSignal
参数
active:boolean

Running
功能: AvatarBehavior
Humanoid.Running(speed:number):RBXScriptSignal
参数
speed:number
代码示例
人形体运行
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local function onRunning(speed: number)
if speed > 0 then
print(`{localPlayer.Name} 在跑`) -- 打印玩家是否正在跑
else
print(`{localPlayer.Name} 已停止`) -- 打印玩家是否已停止
end
end
humanoid.Running:Connect(function(speed: number)
onRunning(speed)
end)

Seated
功能: AvatarBehavior
Humanoid.Seated(
active:boolean, currentSeatPart:BasePart
参数
active:boolean
currentSeatPart:BasePart
代码示例
找到玩家的位置
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local function onSeated(isSeated, seat)
if isSeated then
print("我现在坐在: " .. seat.Name .. "!")
else
print("我没有坐在任何地方")
end
end
humanoid.Seated:Connect(onSeated)

StateChanged
功能: AvatarBehavior
代码示例
跳跃粒子
local character = script.Parent
local primaryPart = character.PrimaryPart
-- 创建粒子
local particles = Instance.new("ParticleEmitter")
particles.Size = NumberSequence.new(1)
particles.Transparency = NumberSequence.new(0, 1)
particles.Acceleration = Vector3.new(0, -10, 0)
particles.Lifetime = NumberRange.new(1)
particles.Rate = 20
particles.EmissionDirection = Enum.NormalId.Back
particles.Enabled = false
particles.Parent = primaryPart
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
-- 监听人形状态
local function onStateChanged(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
particles.Enabled = true
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
particles.Enabled = false
end
end
end
humanoid.StateChanged:Connect(onStateChanged)
跳跃冷却
local character = script.Parent
local JUMP_DEBOUNCE = 1
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
task.wait(JUMP_DEBOUNCE)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)

StateEnabledChanged
功能: AvatarBehavior
Humanoid.StateEnabledChanged(
参数
isEnabled:boolean
代码示例
人形状态变化检测器
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local function onStateEnabledChanged(state, enabled)
if enabled then
print(state.Name .. " 已启用")
else
print(state.Name .. " 已禁用")
end
end
humanoid.StateEnabledChanged:Connect(onStateEnabledChanged)

StatusAdded
已弃用

StatusRemoved
已弃用

Strafing
功能: AvatarBehavior
Humanoid.Strafing(active:boolean):RBXScriptSignal
参数
active:boolean

Swimming
功能: AvatarBehavior
Humanoid.Swimming(speed:number):RBXScriptSignal
参数
speed:number

Touched
功能: AvatarBehavior
Humanoid.Touched(
touchingPart:BasePart, humanoidPart:BasePart
参数
touchingPart:BasePart
humanoidPart:BasePart
代码示例
米达斯之触
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local partInfo = {}
local debounce = false
local function onHumanoidTouched(hit, _limb)
if debounce then
return
end
if not hit.CanCollide or hit.Transparency ~= 0 then
return
end
if not partInfo[hit] then
partInfo[hit] = {
BrickColor = hit.BrickColor,
Material = hit.Material,
}
hit.BrickColor = BrickColor.new("Gold")
hit.Material = Enum.Material.Ice
debounce = true
task.wait(0.2)
debounce = false
end
end
local touchedConnection = humanoid.Touched:Connect(onHumanoidTouched)
local function onHumanoidDied()
if touchedConnection then
touchedConnection:Disconnect()
end
-- 撤销所有的黄金
for part, info in pairs(partInfo) do
if part and part.Parent then
part.BrickColor = info.BrickColor
part.Material = info.Material
end
end
end
humanoid.Died:Connect(onHumanoidDied)

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。