Humanoid
The Humanoid is a special object that gives models the functionality of a character. It grants the model with the ability to physically walk around and interact with various components of a Roblox level. Humanoids are always parented inside of a Model, and the model is expected to be an assembly of BasePart and Motor6D; the root part of the assembly is expected to be named HumanoidRootPart. It also expects a part named Head to be connected to the character's torso part, either directly or indirectly. By default, there are two official types of character rigs supplied by Roblox, each with their own set of rules:
R6
- A basic character rig that uses 6 parts for limbs.
- The Head part must be attached to a part named Torso, or the Humanoid will die immediately.
- BodyPart appearances are applied using CharacterMesh objects.
- Certain properties, such as Humanoid.LeftLeg and Humanoid.RightLeg, only work with R6.
R15
- More complex than R6, but also far more flexible and robust.
- Uses 15 parts for limbs.
- The Head part must be attached to a part named UpperTorso or the Humanoid will die immediately.
- BodyPart appearances have to be assembled directly.
- Can be dynamically rescaled by using special NumberValue objects parented inside of the Humanoid.
- The Humanoid will automatically create Vector3Value objects named OriginalSize inside of each limb.
- If a NumberValue is parented inside of the Humanoid and is named one of the following, it will be used to control the scaling functionality:
- BodyDepthScale
- BodyHeightScale
- BodyWidthScale
- HeadScale
Code Samples
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 -- Is the character walking?
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
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)
Summary
Properties
Sets whether the character will automatically jump when they hit an obstacle as a player on a mobile device.
AutoRotate sets whether or not the Humanoid will automatically rotate to face in the direction they are moving in.
When Enabled, AutomaticScalingEnabled causes the size of the character to change in response to the values in the Humanoid's child scale values changing.
Determines whether a Humanoid's joints break when in the Dead state.
An offset applied to the Camera's subject position when its CameraSubject is set to this Humanoid.
Controls the distance behavior of the humanoid's name and health display.
Sets the text of a Humanoid, displayed above their head.
Describes the current health of the Humanoid on the range [0, Humanoid.MaxHealth].
Used in conjunction with the Humanoid.DisplayDistanceType property to control the distance from which a humanoid's health bar can be seen.
Controls when the humanoid's health bar is allowed to be displayed.
Determines the distance off the ground the Humanoid.RootPart should be.
If true, the Humanoid jumps with an upwards force equal to the value of its Humanoid.JumpPower property or the height of Humanoid.JumpHeight, depending on the value of Humanoid.UseJumpPower.
Provides control over the height that the Humanoid jumps to.
The maximum value of a Humanoid's Humanoid.Health.
The maximum slope angle that a humanoid can walk on without slipping.
Describes the direction that the Humanoid is walking in.
Used in conjunction with the Humanoid.DisplayDistanceType property to control the distance from which a humanoid's name can be seen.
Controls whether a humanoid's name and health bar can be seen behind walls or other objects.
Determines whether the Humanoid is currently in the PlatformStanding HumanoidStateType.
Allows developers to disable the behavior where a player Character|character dies if the Neck Motor6D is removed or disconnected even momentarily.
Describes whether this Humanoid is utilizing the legacy R6 character rig, or the new R15 character rig.
A reference to the seat that a Humanoid is currently sitting in, if any.
Determines whether the JumpHeight (false) or Humanoid.JumpPower (true) property is used.
Describes the Humanoid's maximum movement speed in studs/sec.
A reference to a part whose position is trying to be reached by a humanoid.
The position that a humanoid is trying to reach, after a call to Humanoid:MoveTo() is made.
Methods
Attaches the specified Accessory to the Humanoid's parent.
Assembles a tree of Motor6D joints by attaching together Attachment objects in a Humanoid's character.
Set the Humanoid to enter the given HumanoidStateType.
Returns an array of Accessories that the Humanoid's parent is currently wearing.
Returns back a copy of the Humanoid's cached HumanoidDescription, which describes its current look.
Pass a body part to this function (the body part should be a sibling of Humanoid, and a child of a Model) to get the BodyPartR15 of the Part.
Returns whether a HumanoidStateType is enabled for the Humanoid.
Causes the Humanoid to walk in the given direction.
Causes the Humanoid to attempt to walk to the given location by setting the Humanoid.WalkToPoint and Humanoid.WalkToPart properties.
Dynamically replaces a Humanoid body part with a different part.
Sets whether a given HumanoidStateType is enabled for the Humanoid.
Lowers the Humanoid.Health of the Humanoid by the given amount if it is not protected by a ForceField.
Makes the character's look match that of the passed in HumanoidDescription.
Makes the character's look match that of the passed in HumanoidDescription (even after external changes).
Events
Fires when the speed at which a Humanoid is climbing changes.
Fires when the Humanoid enters or leaves the FallingDown HumanoidStateType.
Fires when the Humanoid enters or leaves the Freefall HumanoidStateType.
Fires when the Humanoid enters or leaves the GettingUp HumanoidStateType.
Fires when the Humanoid.Health changes (or when the Humanoid.MaxHealth is set).
Fires when the Humanoid enters and leaves the Jumping HumanoidStateType.
Fires when the Humanoid finishes walking to a goal declared by Humanoid:MoveTo().
Fires when the Humanoid enters or leaves the PlatformStanding HumanoidStateType.
Fires when the Humanoid enters or leaves the Ragdoll HumanoidStateType.
Fires when the speed at which a Humanoid is running changes.
Fired when a Humanoid either sits in a Seat or VehicleSeat or gets up.
Fired when the state of the Humanoid is changed.
Fires when Humanoid:SetStateEnabled() is called on the Humanoid.
Fires when the Humanoid enters or leaves the StrafingNoPhysics HumanoidStateType.
Fires when one of the Humanoid's limbs come in contact with another BasePart.
Properties
AutoJumpEnabled
AutoJumpEnabled sets whether or not the Humanoid will attempt to automatically jump over an obstacle it is walking towards.
Currently, this property only works when the following conditions are true:
- The Humanoid's character model is the Player.Character of a Player.
- The Player in question is using touch controls.
When a player's character spawns, the property's value matches the player's Player.AutoJumpEnabled property - which in turn matches the StarterPlayer.AutoJumpEnabled property.
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- Update button text
if player.AutoJumpEnabled then
button.Text = "Auto-Jump is ON"
else
button.Text = "Auto-Jump is OFF"
end
-- Reflect the property in the player's character, if they have one
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- Toggle auto-jump
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- Update everything else
update()
end
button.Activated:Connect(onActivated)
update()
AutoRotate
The AutoRotate property describes whether or not the Humanoid will automatically rotate to face in the direction they are moving. When set to true, the character model will gradually turn to face their movement direction as the Humanoid walks around. When set to false, the character model will remain fixated in its current rotation, unless a rotating force is applied to the HumanoidRootPart.
If the character model happens to be the character of a player, then the behavior of the Humanoid's rotation is influenced by the UserGameSetting's RotateType property.
When the AutoRotate property is set to true, the RotateType property has the following effects on the Humanoid's rotation:
RotationType | Behavior | Context |
---|---|---|
MovementRelative | ||
CameraRelative | Character will rotate to face in the direction of the camera. | Player has their camera zoomed into first-person, or they are in shift-lock mode. |
Code Samples
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() .. " can no longer auto-rotate!")
humanoid.AutoRotate = false
else
print(humanoid:GetFullName() .. " can now auto-rotate!")
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
AutomaticScalingEnabled
The Humanoid has six child scale values including BodyDepthScale, BodyHeightScale, BodyProportionScale, BodyTypeScale, BodyWidthScale, HeadScale. Changing the value of any of these causes the character's body parts and accessories to change size, but only if AutomaticScalingEnabled is true.
BreakJointsOnDeath
Determines whether a Humanoid's joints break when in the Dead state. Defaults to true.
If it is set to false, BreakJoints will not be called on death or after death. If it is set to true, the existing break-joints-every-frame behavior will be used.
CameraOffset
The CameraOffset property specifies an offset to the Camera's subject position when its Camera.CameraSubject is set to this Humanoid.
The offset is applied in object-space, relative to the orientation of the Humanoid's HumanoidRootPart. For example, an offset Vector3 value of (0, 10, 0) offsets the player's camera to 10 studs above the player's humanoid.
Code Samples
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 -- Is the character walking?
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
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)
DisplayDistanceType
The DisplayDistanceType property controls the distance behavior of the humanoid's name and health display. This property is set using the HumanoidDisplayDistanceType enum with three available values, each with their own set of rules:
- When set to Viewer, the humanoid sees the name/health of other humanoids within range of its own NameDisplayDistance and HealthDisplayDistance.
- When set to Subject, the humanoid takes full control over its own name and health display through its NameDisplayDistance and HealthDisplayDistance values.
- When set to None, the humanoid's name and health bar do not appear under any circumstances.
See Character Name/Health Display for an in-depth guide on controlling the appearance of character names and health bars.
Code Samples
local humanoid = script.Parent
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
humanoid.HealthDisplayDistance = 0
humanoid.NameDisplayDistance = 100
DisplayName
DisplayName is a property that determines the Humanoid's name display when visible. By default, a new Humanoid will have the value of an empty string. If DisplayName is an empty string, the humanoid's name display will default to the humanoid's parent's name property.
Player Character Loading When players load their character, either automatically or through the use of LoadCharacter(), the Humanoid that is created by the engine will have its DisplayName property set to the player's DisplayName property.
StarterCharacter and StarterHumanoid When a Humanoid named StarterHumanoid is parented to StarterPlayer, or when a Humanoid is present in a Model named StarterCharacter, the DisplayName property will be respected when Characters are loaded by Players in the game. The engine will only override the DisplayName property of the Humanoid with the DisplayName property of the player if the StarterHumanoid's DisplayName property is an empty string.
EvaluateStateMachine
FloorMaterial
This is a read-only property that describes the Material the Humanoid is currently standing on. It works with both regular Parts and Terrain voxels.
The code sample below demonstrates how to listen to when this property changes using Instance:GetPropertyChangedSignal(). When the material the humanoid is standing on changes, it will print a message indicating the new material being stood on.
local Humanoid = route.to.humanoid
Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
print("New value for FloorMaterial: " .. tostring(Humanoid.FloorMaterial))
end)
Caveats
- When the Humanoid is not standing on a floor, the value of this property will be set to Air.
- This occurs because Enum properties cannot have an empty value.
- This can cause some confusion if a part has its material is set to Air, though in practice, parts are not supposed to use that material in the first place.
- The character model of the Humanoid must be able to collide with the floor, or else it will not be detected.
- You cannot test if the Humanoid is swimming with this property. You should instead use its Humanoid:GetState() function.
Health
Health is a property that represents the current health of the Humanoid. The value is restricted to the range [0, Humanoid.MaxHealth]. If the Humanoid is dead, Health is continually set to 0.
Dealing Damage
The TakeDamage function should be used to subtract from Health. If a Humanoid has a ForceField as a sibling, the function will not lower Health.
Regeneration
If there is no Script named "Health" within StarterCharacterScripts, a passive health regeneration script is automatically inserted. This causes players' characters to spawn with the same health regeneration script, which adds 1% of MaxHealth to Health each second, while the Humanoid is not dead. To disable this health regeneration behavior, add an empty Script named "Health" to StarterCharacterScripts.
Health Bar Display
When Health is less than MaxHealth, a health bar is displayed under the Humanoid's name in-game. The display behavior of the health bar is dependent on the HealthDisplayDistance and HealthDisplayType.
A Player will not see their own name and health bar above their Character. Instead, it is displayed in the top right corner of the screen on the top bar. The health bar is visible when Health is less than MaxHealth.
Death
When the value of the character's health reaches 0, the Humanoid automatically transitions to the Dead HumanoidStateType. In this state, Health is locked to 0; however, there is no error or warning for setting the Health of a dead Humanoid to a positive nonzero value.
HealthDisplayDistance
The HealthDisplayDistance property is a number used in conjunction with the Humanoid.DisplayDistanceType property to control the distance from which a humanoid's health bar can be seen.
See Character Name/Health Display for an in-depth guide on controlling the appearance of character names and health bars.
Code Samples
local humanoid = script.Parent
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
humanoid.HealthDisplayDistance = 0
humanoid.NameDisplayDistance = 100
HealthDisplayType
HealthDisplayType controls when a humanoid's health bar is allowed to be displayed. By default, this property is set to DisplayWhenDamaged, which makes the health bar only display when a humanoid's Humanoid.Health is less than its Humanoid.MaxHealth. It can also be set to AlwaysOn, which makes the health bar always display, or AlwaysOff, which prevents it from ever displaying.
This property functions independently of the humanoid's HealthDisplayDistance property, which is responsible for making the health bar fade out at certain distances. If HealthDisplayType is set to AlwaysOn, it will still fade out depending the how Humanoid.HealthDisplayDistance is configured.
See Character Name/Health Display for an in-depth guide on controlling the appearance of character names and health bars.
HipHeight
HipHeight determines the distance (in studs) off the ground the Humanoid.RootPart should be when the Humanoid is standing. The RigType influences the way this property behaves:
HipHeight for R15 Humanoids
With R15 rigs, a suitable HipHeight is preset to ensure the height of the Humanoid.RootPart is correct. The height of the legs is not used. The overall height of the Humanoid can be described in the following formula:
Height = (0.5 * RootPart.Size.Y) + HipHeight
HipHeight for R6 Humanoids
For R6 rigs, the RootPart's height is determined by the height of the character's legs and Humanoid.RootPart. HipHeight instead describes a relative offset. The overall height of the Humanoid can be described in the following formula:
Height = LeftLeg.Size.Y + (0.5 * RootPart.Size.Y) + HipHeight
Jump
If true, the Humanoid jumps with an upwards force equal to the value of its Humanoid.JumpPower property or the height of Humanoid.JumpHeight, depending on the value of Humanoid.UseJumpPower.
If Humanoid.UseJumpPower is set to true, Humanoids are able to jump roughly 7.2 studs high by default, depending on both the Workspace's Workspace.Gravity, and the Humanoid.JumpPower of the humanoid itself.
If Humanoid.UseJumpPower is set to false, the height of the jump can be set explicitly with Humanoid.JumpHeight.
JumpHeight
Provides control over the height a Humanoid jumps in studs. The starting value of this property is determined by the value of StarterPlayer.CharacterJumpHeight, which defaults to 7.2.
This property is only visible in the Properties window if Humanoid.UseJumpPower is set to false, as it would not be relevant otherwise.
This property can be used to adjust the height that a humanoid can jump, allowing developers to remove jumping, allow dynamically adjustable jump height based on character stats or raise the jump height (as if on the moon or such).
JumpPower
Determines how much upwards force is applied to the Humanoid when jumping. The starting value of this property is determined by the value of StarterPlayer.CharacterJumpPower, which defaults to 50 and is constrained between 0 and 1000.
This property is only visible in the Properties window if `Class.Humanoid.UseJumpPower`` is set to true, as it would not be relevant otherwise.
Note:
- Jumps are also influenced by the Workspace.Gravity property which determines the acceleration due to gravity.
- Although setting this property to 0 will prevent the Humanoid from jumping, developers are advised to disable the "Jumping" state using the Humanoid:SetStateEnabled() function.
MaxHealth
The maximum value of a Humanoid's Humanoid.Health. The value of this property is used with the value of the Humanoid.Health property to size the default health bar display.
When a Humanoid's Humanoid.Health reaches its maximum value, its health bar may not be displayed anymore, depending on its Humanoid.HealthDisplayType property, as seen below:
MaxSlopeAngle
This property determines the maximum slope angle that a humanoid can climb. If the angle of a slope is greater than a humanoid's MaxSlopeAngle, they will slide down the slope.
When a character spawns, this property is set according to the value of StarterPlayer.CharacterMaxSlopeAngle.
The value of this property is constrained to values between 0° and 89°. It defaults to 89°, so humanoids can climb pretty much any slope they want by default.
Code Samples
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char:FindFirstChild("Humanoid")
h.MaxSlopeAngle = 30
MoveDirection
MoveDirection is a read-only property that describes the direction a Humanoid is walking in, as a unit vector or zero length vector. The direction is described in world space.
Because this property is read-only, it cannot be set by a Script or LocalScript.
Code Samples
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 -- Is the character walking?
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
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)
NameDisplayDistance
The NameDisplayDistance property is a number used in conjunction with the Humanoid.DisplayDistanceType property to control the distance from which a humanoid's name can be seen.
See Character Name/Health Display for an in-depth guide on controlling the appearance of character names and health bars.
NameOcclusion
Controls whether a humanoid's name and health bar can be seen behind walls or other objects. This property is a NameOcclusion value and can be configured to occlude all names, enemy names, or disable occlusion entirely.
In cases where the LocalPlayer has no Humanoid associated with it, this property instead applies to the subject Humanoid.
See Character Name/Health Display for an in-depth guide on controlling the appearance of character names and health bars.
Code Samples
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
PlatformStand describes whether the Humanoid is currently in the PlatformStanding HumanoidStateType. When true, the Humanoid is in a state where it is free-falling and cannot move. This state behaves similar to sitting, except that jumping does not free the humanoid from the state.
The now-deprecated SkateboardPlatform puts the Humanoid into this state, much like how a Seat causes a sitting state.
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.PlatformStand = true
RequiresNeck
Allows developers to disable the behavior where a player Character|character dies if the Neck Motor6D is removed or disconnected even momentarily. This property defaults to true.
RigType
RigType describes whether a Humanoid is utilizing the legacy R6 character rig, or the newer R15 character rig.
The R6 rig uses 6 visible Parts while the R15 rig uses 15 visible Parts. R15 rigs have more joints than R6 rigs, making them much more versatile when being animated.
Note that if this property is set incorrectly, the Humanoid will not function correctly. For example, if a R15 humanoid's RigType is set to R6, the Humanoid will die as there is no BasePart called Torso connected to a BasePart called Head.
RootPart
A reference to the humanoid's HumanoidRootPart object, the root driving part of the Humanoid that controls a humanoid's movement through the 3D world. This part is normally invisible.
Note that in the case of player characters, RootPart is the same as the Model.PrimaryPart of the Player.Character model.
SeatPart
SeatPart is a reference to the seat that a Humanoid is currently sitting in, if any. The value of this property can be either a Seat, or a VehicleSeat. It will be nil if the Humanoid is not currently sitting in a seat.
Note:
- For a bool describing if the Humanoid is currently sitting or not, see Humanoid.Sit
Sit
The Sit property is a boolean that indicates whether the Humanoid is currently sitting. Humanoids can be forced into a sitting state by setting this property's value to true. If the Humanoid isn't attached to a seat while in its sitting state, it will trip over with no collision in its legs. A Humanoid can escape from the sitting state by jumping.
Note:
- The Seat or VehicleSeat the Humanoid is sitting on can be obtained using the Humanoid.SeatPart property
- It is possible to detect when a Humanoid sits by connecting to the Humanoid.Seated event.
TargetPoint
Do not use This property only works with Experimental Mode enabled, which has been entirely discontinued.
This property describes a 3D position in space where the Player controlling this Humanoid last clicked with a Tool equipped.
This property is primarily used by classic tools to determine what a humanoid is targeting when they activate a tool. If you give an NPC a classic rocket launcher, set their TargetPoint, and then call the tool's Tool:Activate() function, you can make the NPC fire a rocket at the target point.
UseJumpPower
When a character spawns, this property is set according to the value of StarterPlayer.CharacterUseJumpPower which defaults to true.
When a character spawns, this property is set according to the value of StarterPlayer.CharacterUseJumpPower which defaults to true.
When jumping, with this set to true, the Humanoid.JumpHeight value is used to ensure the humanoid jumps to that height. With this set to false, the Humanoid.JumpPower value is used to apply an upward force.
WalkSpeed
WalkSpeed is a property that describes how quickly this Humanoid is able to walk, in studs per second. This property defaults to the value of StarterPlayer.CharacterWalkSpeed, which defaults to 16, meaning a Roblox Player.Character can move 16 studs in any direction each second by default.
Note:
- When controlled on a mobile device or a gamepad, a humanoid can walk slower than their WalkSpeed if the controlling joystick is moved closer to its center
- Roblox's default animation script scales a humanoid's movement animations based on how fast it is moving relative to the default speed of 16 studs/sec
- The speed the Humanoid is currently walking at can be obtained using the Humanoid.Running event
- Movement speed is reduced to 87.5% WalkSpeed when swimming and 70% WalkSpeed when climbing
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 0
WalkToPart
WalkToPart is a reference to a part that the Humanoid is trying to reach. This property is normally set when a part is passed as the 2nd argument of the Humanoid's Humanoid:MoveTo() function.
When WalkToPart is set and a humanoid is actively trying to reach the part, it will keep updating its Vector3 goal to be the position of the part, plus the Humanoid.WalkToPoint translated in object space relative to the rotation of the part.
This can be described in Lua as:
goal = humanoid.WalkToPart.CFrame:pointToObjectSpace(humanoid.WalkToPoint)
Caveats
- Setting the value of WalkToPart isn't sufficient enough to make a humanoid start following a part.
- The Humanoid is prompted to start attempting to reach a goal when the value of WalkToPoint is changed.
- This may be changed in the future.
- The reach goal state of a humanoid will timeout after 8 seconds if it doesn't reach its goal.
- This is done so that NPCs won't get stuck waiting for Humanoid.MoveToFinished to fire.
- If you don't want this to happen, you should repeatedly call MoveTo so that the timeout will keep resetting.
WalkToPoint
WalkToPoint describes the 3D position in space that a humanoid is trying to reach, after having been prompted to do so by the Humanoid's Humanoid:MoveTo() function.
If a humanoid's Humanoid.WalkToPart is set, the goal is set by transforming WalkToPoint relative to the parts position and rotation. If WalkToPart is not set, then the humanoid will try to reach the 3D position specified by WalkToPoint directly.
Caveats
- The value of WalkToPoint must be changed to a different value in order for the humanoid to start walking towards it.
- If you want to make a humanoid walk to 0,0,0, you should use the Humanoid's MoveTo function.
- This may be changed in the future.
- The reach goal state of a humanoid will timeout after 8 seconds if it doesn't reach its goal.
- This is done so that NPCs won't get stuck waiting for Humanoid.MoveToFinished to fire.
- If you don't want this to happen, you should repeatedly call MoveTo so that the timeout will keep resetting.
Code Samples
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)
Methods
AddAccessory
The AddAccessory function attaches the specified Accessory to the Humanoid's parent.
How are Accessories attached to Humanoids?
When this function is called, the Accessory is parented to the Humanoid's parent and then attached.
An Accessory is attached to the character by searching for an Attachment in the Humanoid's parent that shares the same name as an Attachment in the accessory's Handle Part. If one is found, the Handle part will be connected to the parent of the Attachment using a Weld. This weld will be configured so the Attachments occupy the same space.
If the required Attachment can not be found, then the Accessory will remain parented to the Humanoid's parent but it will be unattached.
Typically accessory welds are created on the server. Under certain circumstances, they can be created on the client. In these situations, client-sided calls to Humanoid.AddAccessory may not always produce the desired behavior and you can use Humanoid.BuildRigFromAttachments to force the expected weld creation.
Parameters
Returns
Code Samples
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)
BuildRigFromAttachments
BuildRigFromAttachments assembles a tree of Motor6D joints for a Humanoid. Motor6D joints are required for the playback of Animations
Starting from the humanoid's Humanoid.RootPart, the function collects all Attachments parented in the current part, whose name ends with "RigAttachment". It then searches for a matching attachment in the character that shares the same name as the attachment. Using those two attachments, a Motor6D joint is generated based on the parts associated with the two attachments, and the Attachment.CFrames of the attachments.
BuildRigFromAttachments also scales the character and sets body colors.
See the provided code sample below to see how this function works.
Returns
Code Samples
local function createJoint(jointName, att0, att1)
local part0, part1 = att0.Parent, att1.Parent
local newMotor = part1:FindFirstChild(jointName)
if not (newMotor and newMotor:IsA("Motor6D")) then
newMotor = Instance.new("Motor6D")
end
newMotor.Name = jointName
newMotor.Part0 = part0
newMotor.Part1 = part1
newMotor.C0 = att0.CFrame
newMotor.C1 = att1.CFrame
newMotor.Parent = part1
end
local function buildJointsFromAttachments(part, characterParts)
if not part then
return
end
-- first, loop thru all of the part's children to find attachments
for _, attachment in pairs(part:GetChildren()) do
if attachment:IsA("Attachment") then
-- only do joint build from "RigAttachments"
local attachmentName = attachment.Name
local findPos = attachmentName:find("RigAttachment")
if findPos then
-- also don't make double joints (there is the same named
-- rigattachment under two parts)
local jointName = attachmentName:sub(1, findPos - 1)
if not part:FindFirstChild(jointName) then
-- try to find other part with same rig attachment name
for _, characterPart in pairs(characterParts) do
if part ~= characterPart then
local matchingAttachment = characterPart:FindFirstChild(attachmentName)
if matchingAttachment and matchingAttachment:IsA("Attachment") then
createJoint(jointName, attachment, matchingAttachment)
buildJointsFromAttachments(characterPart, characterParts)
break
end
end
end
end
end
end
end
end
local function buildRigFromAttachments(humanoid)
local rootPart = humanoid.RootPart
assert(rootPart, "Humanoid has no HumanoidRootPart.")
local characterParts = {}
for _, descendant in ipairs(humanoid.Parent:GetDescendants()) do
if descendant:IsA("BasePart") then
table.insert(characterParts, descendant)
end
end
buildJointsFromAttachments(rootPart, characterParts)
end
local humanoid = script.Parent:WaitForChild("Humanoid")
buildRigFromAttachments(humanoid)
local AssetService = game:GetService("AssetService")
local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")
local PACKAGE_ASSET_ID = 193700907 -- Circuit Breaker
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:GetProductInfo(packageAssetId)
local character, humanoid = createBaseCharacter()
character.Name = packageAssetInfo.Name
local assetIds = AssetService:GetAssetIdsForPackage(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
This function causes the Humanoid to enter the given HumanoidStateType.
The humanoid state describes the activity the Humanoid is currently doing.
You should check the page for HumanoidStateType for more information on what particular states do as some have unintuitive names. For example, running describes a state where the Humanoid's legs are on the ground, including when stationary
Due to the default behavior of the Humanoid some states will automatically be changed when set to. For example:
- Setting the state to 'Swimming' when the Humanoid is not in the water will lead to it being automatically set to 'GettingUp'
- As it is unused, setting the state to 'PlatformStanding' will lead to it being automatically set to 'Running'
See also:
- To enable or disable a particular state use Humanoid:SetStateEnabled()
- To get the current state use Humanoid:GetState()
Parameters
The HumanoidStateType that the Humanoid is to perform.
Returns
Code Samples
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
This function makes the Humanoid equip the given Tool.
The below example would cause a Player to equip a tool in Workspace named 'Tool'.
local Players = game:GetService("Players")local player = Players:FindFirstChildOfClass("Player")if player and player.Character thenlocal humanoid = player.Character:FindFirstChildOfClass("Humanoid")if humanoid thenlocal tool = workspace:FindFirstChild("Tool")if tool thenhumanoid:EquipTool(tool)endendend
When this function is called, the humanoid will automatically unequip any Tools that it currently has equipped
Although they will be equipped, Tools for which Tool.RequiresHandle is true will not function if they have no handle, regardless if this function is used to equip them or not
See also:
- To unequip tools, use Humanoid:UnequipTools()
Parameters
Returns
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character.Humanoid
-- Create a new randomly colored part at *pos* world position
local function spawnPart(position)
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Position = position
part.Parent = game.Workspace
part.BrickColor = BrickColor.random()
end
-- Spawn a new part at TargetPoint when the tool is activated
function onActivated()
spawnPart(humanoid.TargetPoint)
end
-- Make a new tool and handle and put it in the player's Backpack
local function makeTool()
-- Create tool
local tool = Instance.new("Tool")
tool.Parent = player:WaitForChild("Backpack")
-- Create tool handle
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Parent = tool
handle.BrickColor = BrickColor.random()
-- Enable and equip tool
tool.Enabled = true
humanoid:EquipTool(tool)
-- Handle tool use
tool.Activated:Connect(onActivated)
end
-- Make a new tool when the LocalScript first runs
makeTool()
GetAccessories
This function returns an array of Accessories that the Humanoid's parent is currently wearing. All Accessory objects parented to the Humanoid's parent will be included, regardless of if they are attached or not. If the humanoid is not wearing any accessories, the array will be empty.
If the Humanoid has no Accessories an empty array will be returned
See also:
Returns
An array of Accessories that are parented to the Humanoid's parent.
Code Samples
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local numAccessories = #character:GetAccessories()
print(("Destroying %d accessories for %s"):format(numAccessories, player.Name))
local humanoid = character:FindFirstChildOfClass("Humanoid")
humanoid:RemoveAccessories()
end)
-- Make sure we disconnect our connection to the player after they leave
-- to allow the player to get garbage collected
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)
GetAppliedDescription
This blocking function returns back a copy of the Humanoid's cached HumanoidDescription, which describes its current look.
This can be used to quickly determine a player's look and to assign their look to other players using the Humanoid:ApplyDescription() function.
See also:
- Players:GetHumanoidDescriptionFromUserId(), gives back a HumanoidDescription which describes the Avatar for the passed in user
- Players:GetHumanoidDescriptionFromOutfitId(), gives back a HumanoidDescription whose parameters are initialized to match that of the passed in server-side outfit asset
- Player:LoadCharacterWithHumanoidDescription(), spawns a player with the look from the HumanoidDescription Instance passed in
Returns
GetBodyPartR15
This function returns what BodyPartR15 a Part is, or BodyPartR15.Unknown if the part is not an R15 body part. This function allows developers to retrieve player body parts independent of what the actual body part names are, instead returning an Enum.
It can be used in conjunction with Humanoid:ReplaceBodyPartR15(). For example, if a player's body part touches something, this function will return get a part instance. Developers can then look up what part of the body that was, like head or arm. Then depending on what that part was, developers can either perform some gameplay action or replace that part with some other part - perhaps showing damage.
This function can be useful for games where hit location is important. For example, it can be used to determine if a player is hit in the leg and then slow them down based on the injury.
Parameters
The specified part being checked to see if it is an R15 body part.
Returns
The specified part's R15 body part type or unknown if the part is not a body part.
GetLimb
This function returns the Limb enum that is associated with the given Part
This function works for both R15 and R6 rigs, for example:
-- For R15print(humanoid:GetLimb(character.LeftUpperLeg)) -- Enum.Limb.LeftLegprint(humanoid:GetLimb(character.LeftLowerLeg)) -- Enum.Limb.LeftLegprint(humanoid:GetLimb(character.LeftFoot)) -- Enum.Limb.LeftLeg-- For R6print(humanoid:GetLimb(character:FindFirstChild("Left Leg"))) -- Enum.Limb.LeftLeg
GetLimb will throw an error if the Part's parent is not set to the Humanoid's parent.
Parameters
Returns
Code Samples
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 .. " is part of limb " .. limb.Name)
end
end
GetState
This function returns the Humanoid's current HumanoidStateType.
The humanoid state describes the activity the Humanoid is currently doing, such as jumping or freefalling.
See also:
- To change the Humanoid's state use Humanoid:ChangeState()
- To enable or disable a particular state use Humanoid:SetStateEnabled()
- For more information on the different states available, see HumanoidStateType
Returns
The current HumanoidStateType of the Humanoid.
Code Samples
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
The GetStateEnabled function returns whether a HumanoidStateType is enabled for the Humanoid.
The humanoid state describes the activity the humanoid is currently doing.
When a particular HumanoidStateType is disabled, the humanoid can never enter that state. This is true regardless if the attempt to change state is made using Humanoid:ChangeState() or Roblox internal humanoid code.
See also:
- For an event that fires when a humanoid state is enabled or disabled see Humanoid.StateEnabledChanged
- To enable or disable a Humanoid state use Humanoid:SetStateEnabled()
Parameters
The given HumanoidStateType.
Returns
Whether the given HumanoidStateType is enabled.
Code Samples
local humanoid = script.Parent:WaitForChild("Humanoid")
-- Set state
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
-- Get state
print(humanoid:GetStateEnabled(Enum.HumanoidStateType.Jumping)) -- false
Move
This function causes the Humanoid to walk in the given Vector3 direction.
By default, the direction given is in world terms. If the relativeToCamera parameter is true however the direction given is relative to the CurrentCamera's CFrame. As the negative Z direction is considered 'forwards' in Roblox, the following code would make the Humanoid walk in the direction of the Workspace.CurrentCamera.
humanoid:Move(Vector3.new(0, 0, -1), true)
When this function is called, the Humanoid will move until the function is called again. However, if the default control scripts are being used this function will be overwritten when called on Player Characters. This can be avoided by either not using the default control scripts, or calling this function every frame using RunService:BindToRenderStep() (see example).
This function can be called on the server, but this should only be done when the server has network ownership of the Humanoid's assembly.
See also:
- To make aHumanoid walk to a point, use the Humanoid:MoveTo() function
- For Players the Player:Move() function exists that calls this function
Parameters
The direction to walk in.
True if the direction parameter should be taken as relative to the Workspace.CurrentCamera.
Returns
Code Samples
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
This function causes the Humanoid to attempt to walk to the given location by setting the Humanoid.WalkToPoint and Humanoid.WalkToPart properties.
The location and part parameters correspond with what Humanoid.WalkToPoint and Humanoid.WalkToPart will be set to.
If the part parameter is specified, the Humanoid will still attempt to walk to the point. However, if the part moves then the point the Humanoid is walking to will move to be at the same position relative to the part. If the part parameter is not specified, then the position the Humanoid is walking to will not change.
The reach goal state of a humanoid will timeout after 8 seconds if it doesn't reach its goal. This is done so that NPCs won't get stuck waiting for Humanoid.MoveToFinished to fire. If you don't want this to happen, you should repeatedly call MoveTo so that the timeout will keep resetting.
Parameters
The position to set Humanoid.WalkToPoint to.
The BasePart to set Humanoid.WalkToPart to.
Returns
Code Samples
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)
RemoveAccessories
This function removes all Accessories worn by the Humanoid's parent. When this function is called, all Accessories sharing an Instance.Parent with the Humanoid will be removed. For Player Characters this will remove all hats and other accessories.
This function removes Accessories by calling Instance:Destroy() on them. This means the Parents of the accessories are set to nil and locked.
See also:
- To attach an Accessory use the Humanoid:AddAccessory() function
Returns
Code Samples
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local numAccessories = #character:GetAccessories()
print(("Destroying %d accessories for %s"):format(numAccessories, player.Name))
local humanoid = character:FindFirstChildOfClass("Humanoid")
humanoid:RemoveAccessories()
end)
-- Make sure we disconnect our connection to the player after they leave
-- to allow the player to get garbage collected
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)
ReplaceBodyPartR15
ReplaceBodyPartR15 dynamically replaces a R15/Rthro limb part in a Humanoid with a different part. The part is automatically scaled as normal. In the image below, a R15 avatar has had their right hand replaced with a slightly larger version (also pictured).
This function is useful for modifying characters during gameplay or building characters from a base rig. The related function GetBodyPartR15 can come in handy when using this function.
The name of the part passed in should match with the name of the BodyPartR15 Enum passed in.
Parameters
The body part to replace. BodyPartR15.Unknown will fail.
Returns
SetStateEnabled
This function sets whether a given HumanoidStateType is enabled for the Humanoid.
The humanoid state describes the activity the Humanoid is currently doing.
When a particular HumanoidStateType is disabled, the Humanoid can never enter that state. This is true regardless if the attempt to change state is made using Humanoid:ChangeState() or Roblox internal Humanoid code.
Parameters
The HumanoidStateType to be enabled or disabled.
True if this state is to be enabled, false if it is to be disabled.
Returns
Code Samples
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
This function lowers the Humanoid.Health of the Humanoid by the given amount if it is not protected by a ForceField
This function accepts negative values for the amount parameter. This will increase the humanoid's Humanoid.Health. However this will only have an effect if no ForceField is present.
How do ForceFields protect against TakeDamage
A Humanoid is considered protected by a ForceField if a ForceField meets one of the following criteria:
To do damage to a Humanoid irrespective of any ForceFields present, set Humanoid.Health directly.
For more information on how ForceFields protect Humanoids see the ForceField page
Parameters
The damage, or amount to be deduced from the Humanoid.Health.
Returns
Code Samples
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid:TakeDamage(99)
UnequipTools
This function unequips any Tool currently equipped by the Humanoid
The unequipped Tool will be parented to the Backpack of the Player associated with the Humanoid.
If no Tool is equipped, this function will do nothing.
Although Tools can be equipped by NPCs (Non Player Characters), this function only works on Humanoids with a corresponding Player. This is because a Backpack object is required to parent the unequipped Tool to.
See also:
- To instead equip a Tool, use Humanoid:EquipTool()
Returns
Code Samples
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
ContextActionService:BindAction("unequipTools", function(_, userInputState)
if userInputState == Enum.UserInputState.Begin then
if player.Character then
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:UnequipTools()
end
end
end
end, false, Enum.KeyCode.U)
ApplyDescription
This yield function makes the character's appearance match the specification of the passed in HumanoidDescription. A copy of the passed HumanoidDescription is cached as the HumanoidDescription for the Humanoid.
It allows you to quickly set a character's appearance and store the specification of that appearance.
This function is optimized through making the assumption that only this function is used to change the appearance of the character, and no changes are made through other means between calls. If changes are made to the character between calls. Then this function may not make the character reflect the passed in HumanoidDescription accurately. If you want to use this function in conjunction with other means of updating the character, Humanoid:ApplyDescriptionReset() will always ensure the character reflects the passed in HumanoidDescription.
See also:
- Humanoid:ApplyDescriptionReset(), Makes the character's look match that of the passed in HumanoidDescription (even after external changes)
- Humanoid:GetAppliedDescription(), returns the HumanoidDescription currently applied to the Humanoid
- Players:GetHumanoidDescriptionFromUserId(), gives back a HumanoidDescription which describes the Avatar for the passed in user
- Players:GetHumanoidDescriptionFromOutfitId(), gives back a HumanoidDescription whose parameters are initialized to match that of the passed in server-side outfit asset
- Player:LoadCharacterWithHumanoidDescription(), spawns a player with the look from the HumanoidDescription Instance passed in
Parameters
The HumanoidDescription Instance which you want to set the character to match.
Returns
ApplyDescriptionReset
This yield function makes the character's appearance match the specification of the passed in HumanoidDescription. A copy of the passed HumanoidDescription is cached as the HumanoidDescription for the Humanoid.
It allows you to quickly set a character's appearance and store the specification of that appearance.
This function will always ensure the character reflects the passed in HumanoidDescription, even if changes have been made to the character not using the HumanoidDescription system (i.e not using Humanoid:ApplyDescriptionReset() or Humanoid:ApplyDescription()). This is in contrast to Humanoid:ApplyDescription(), which is optimized and may incorrectly apply a HumanoidDescription if the character has been changed by means other than through the HumanoidDescription system.
See also:
- Humanoid:ApplyDescription(), Makes the character's look match that of the passed in HumanoidDescription.
- Humanoid:GetAppliedDescription(), returns the HumanoidDescription currently applied to the Humanoid
- Players:GetHumanoidDescriptionFromUserId(), gives back a HumanoidDescription which describes the Avatar for the passed in user
- Players:GetHumanoidDescriptionFromOutfitId(), gives back a HumanoidDescription whose parameters are initialized to match that of the passed in server-side outfit asset
- Player:LoadCharacterWithHumanoidDescription(), spawns a player with the look from the HumanoidDescription Instance passed in
Parameters
The HumanoidDescription Instance which you want to set the character to match.
Returns
PlayEmote
If the emote could not be played because the emoteName is not found in the HumanoidDescription this API will give an error. The API will return true to indicate that the emote was played successfully.
Parameters
name of the emote to play.
Returns
successfully played.
Events
Climbing
Fires when the speed at which a Humanoid is climbing changes.
Humanoids can climb up ladders made out of Parts or TrussParts.
Humanoids climb at 70% of their Humanoid.WalkSpeed.
This event will not always fire with a speed of 0 when the Humanoid stops climbing.
See also:
- For swimming and running see the Humanoid.Swimming and Humanoid.Running events
- You can also detect when a Humanoid is climbing using the Humanoid.StateChanged event
- You can disable climbing using the Humanoid:SetStateEnabled() function
Parameters
Code Samples
local Players = game:GetService("Players")
local function onCharacterClimbing(character, speed)
print(character.Name, "is climbing at a speed of", speed, "studs / second.")
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)
Died
This event fires when the Humanoid dies, usually when Humanoid.Health reaches 0. This could be caused either by disconnecting their head from their Humanoid.Torso, or directly setting the health property.
This event only fires if the Humanoid is a descendant of the Workspace. If the Dead HumanoidStateType is disabled it will not fire.
Code Samples
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
print(player.Name, "has died!")
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
FallingDown
The FallingDown event fires when the Humanoid enters and leaves the FallingDown HumanoidStateType.
The Humanoid will enter the GettingUp state 3 seconds after the FallingDown state is enabled. When this happens this event will fire with an active value of false, and Humanoid.GettingUp will fire with an active value of true.
Parameters
Describes whether the Humanoid is entering or leaving the FallingDown HumanoidStateType.
Code Samples
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.Climbing:Connect(function(speed)
print("Climbing speed: ", speed)
end)
humanoid.FallingDown:Connect(function(isActive)
print("Falling down: ", isActive)
end)
humanoid.GettingUp:Connect(function(isActive)
print("Getting up: ", isActive)
end)
humanoid.Jumping:Connect(function(isActive)
print("Jumping: ", isActive)
end)
humanoid.PlatformStanding:Connect(function(isActive)
print("PlatformStanding: ", isActive)
end)
humanoid.Ragdoll:Connect(function(isActive)
print("Ragdoll: ", isActive)
end)
humanoid.Running:Connect(function(speed)
print("Running speed: ", speed)
end)
humanoid.Strafing:Connect(function(isActive)
print("Strafing: ", isActive)
end)
humanoid.Swimming:Connect(function(speed)
print("Swimming speed: ", speed)
end)
FreeFalling
This event fires when the Humanoid enters or leaves the Freefall HumanoidStateType.
The active parameter represents whether the Humanoid is entering or leaving the Freefall state.
Although the Freefall state generally ends when the Humanoid reaches the ground, this event may fire with active equal to false if the state is changed while the Humanoid is falling. For this reason, you should use Humanoid.StateChanged and listen for the Landed state to work out when a Humanoid has landed.
Parameters
Whether the Humanoid is entering or leaving the Freefall HumanoidStateType.
Code Samples
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.Climbing:Connect(function(speed)
print("Climbing speed: ", speed)
end)
humanoid.FallingDown:Connect(function(isActive)
print("Falling down: ", isActive)
end)
humanoid.GettingUp:Connect(function(isActive)
print("Getting up: ", isActive)
end)
humanoid.Jumping:Connect(function(isActive)
print("Jumping: ", isActive)
end)
humanoid.PlatformStanding:Connect(function(isActive)
print("PlatformStanding: ", isActive)
end)
humanoid.Ragdoll:Connect(function(isActive)
print("Ragdoll: ", isActive)
end)
humanoid.Running:Connect(function(speed)
print("Running speed: ", speed)
end)
humanoid.Strafing:Connect(function(isActive)
print("Strafing: ", isActive)
end)
humanoid.Swimming:Connect(function(speed)
print("Swimming speed: ", speed)
end)
GettingUp
This event fires when the Humanoid enters or leaves the GettingUp HumanoidStateType.
The GettingUp HumanoidStateType is a transition state that is activated shortly after the Humanoid enters the FallingDown (3 seconds) or Ragdoll (1 second) HumanoidStateTypes.
When a Humanoid attempts to get back up, this event will first fire with an active parameter of true before shortly after firing again with an active parameter of false.
See also:
- To force a Humanoid to fall over, use the Humanoid:ChangeState() function to change the Humanoid's state to FallingDown
Parameters
Whether the Humanoid is entering or leaving the GettingUp HumanoidStateType.
Code Samples
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.Climbing:Connect(function(speed)
print("Climbing speed: ", speed)
end)
humanoid.FallingDown:Connect(function(isActive)
print("Falling down: ", isActive)
end)
humanoid.GettingUp:Connect(function(isActive)
print("Getting up: ", isActive)
end)
humanoid.Jumping:Connect(function(isActive)
print("Jumping: ", isActive)
end)
humanoid.PlatformStanding:Connect(function(isActive)
print("PlatformStanding: ", isActive)
end)
humanoid.Ragdoll:Connect(function(isActive)
print("Ragdoll: ", isActive)
end)
humanoid.Running:Connect(function(speed)
print("Running speed: ", speed)
end)
humanoid.Strafing:Connect(function(isActive)
print("Strafing: ", isActive)
end)
humanoid.Swimming:Connect(function(speed)
print("Swimming speed: ", speed)
end)
HealthChanged
This event fires when the Humanoid.Health changes. However, it will not fire if the health is increasing from a value equal to or greater than the Humanoid.MaxHealth.
When Humanoid.Health reaches zero, the Humanoid will die and the Humanoid.Died event will fire. This event will fire with a value of zero.
Parameters
The new value of Humanoid.Health.
Code Samples
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("The humanoid's health", (currentHealth > health and "decreased by" or "increased by"), change)
currentHealth = health
end
humanoid.HealthChanged:Connect(onHealthChanged)
end
player.CharacterAdded:Connect(onCharacterAdded)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Paste script into a LocalScript that is
-- parented to a Frame within a Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- black
-- This function is called when the humanoid's health changes
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Change the size of the inner bar
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Change the color of the health bar
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- black
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- yellow
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- green
end
end
-- This function runs is called the player spawns in
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Pattern: update once now, then any time the health changes
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Connect our spawn listener; call it if already spawned
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end
Jumping
This event fires when the Humanoid enters and leaves the Jumping HumanoidStateType.
When a Humanoid jumps this will fire with a active parameter of true before shortly afterwards firing again with an active parameter of false. This does not correspond with when a Humanoid has landed. For that, developers should listen for the Landed HumanoidStateType using Humanoid.StateChanged.
You can disable jumping using the Humanoid:SetStateEnabled() function.
Parameters
Whether the Humanoid is entering or leaving the Jumping HumanoidStateType.
Code Samples
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.Climbing:Connect(function(speed)
print("Climbing speed: ", speed)
end)
humanoid.FallingDown:Connect(function(isActive)
print("Falling down: ", isActive)
end)
humanoid.GettingUp:Connect(function(isActive)
print("Getting up: ", isActive)
end)
humanoid.Jumping:Connect(function(isActive)
print("Jumping: ", isActive)
end)
humanoid.PlatformStanding:Connect(function(isActive)
print("PlatformStanding: ", isActive)
end)
humanoid.Ragdoll:Connect(function(isActive)
print("Ragdoll: ", isActive)
end)
humanoid.Running:Connect(function(speed)
print("Running speed: ", speed)
end)
humanoid.Strafing:Connect(function(isActive)
print("Strafing: ", isActive)
end)
humanoid.Swimming:Connect(function(speed)
print("Swimming speed: ", speed)
end)
MoveToFinished
This event fires when the Humanoid finishes walking to a goal declared by the Humanoid.WalkToPoint and Humanoid.WalkToPart properties.
The Humanoid.WalkToPoint and Humanoid.WalkToPart properties can be set individually, or using the Humanoid:MoveTo() function.
If the Humanoid reaches its goal within 8 seconds, this event will return with reached as true. If the goal is not reached within 8 seconds the Humanoid will stop walking and reached will be false. This timeout can be reset be calling Humanoid:MoveTo() again within the timeout period.
Parameters
Code Samples
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end