The DisplayDistanceType property controls how the humanoid display’s visibility behaves, based on the distance between the
Humanoid and the player’s view.
When a Humanoid’s parent
BaseModel has a part named Head, a visual display of the
Player's name and health is drawn 1.5 studs above the character’s head. This visual display is known as the Humanoid Display.
This property is set using the
Enum/HumanoidDisplayDistanceType enum. There are three available values for this property, each with their own set of rules:
When the DisplayDistanceType is set to None, the humanoid display will not be shown under any circumstances.
When the DisplayDistanceType is set to Viewer, the humanoid display’s visibility is locally controlled by the NameDisplayDistance and HealthDisplayDistance of each Player in the game. For instance, if a player has their display distance properties set to 50, and everyone else has their display distance properties set to 100, then that player will not be able to see the name and health of the humanoid at a distance greater than 50 studs, while everyone else can still see the name and health of the humanoid up to a distance of 100 studs.
In this example all of the NPC characters have their DisplayDistanceType set to Viewer. This means the distance the information will be displayed will be taken from the humanoid that is viewing them. In this case, the player character (who is in the foreground) has its HealthDisplayDistance set to 10 and NameDisplayDistance set to 20. The health bar is only visible on the closest NPC because it is within 10 studs, and the names of only the two closer NPCs are visible because they are within 20 studs.
When the DisplayDistanceType is set to Subject the Humanoid’s name and healthbar will be displayed based on the viewed humanoid’s settings. This is useful when there are specific characters who you want to behave differently from other ones.
In this example all of the NPC characters have their DisplayDistanceType set to Subject. This means the view distance of their information will depend on their individual HealthDisplayDistance and NameDisplayDistance properties.
The NPC on the left has its HealthDisplayDistance and NameDisplayDistance set to 10. Since the NPC is 15 studs away, neither of the displays are visible.
The NPC in the middle has its HealthDisplayDistance set to 10 and NameDisplayDistance set to 20. Since the NPC is 15 studs away, only the name is visible.
The NPC on the right has its HealthDisplayDistance and NameDisplayDistance set to 20. Both name and health are visible, as the NPC is only 15 studs away.
Displaying a Humanoid's Health and Name
This example demonstrates how to set a
Humanoid/NameDisplayDistance properties. These properties determine how a humanoid’s healthbar and name are rendered for a player.
First, we change the DisplayDistanceType to Viewer using
Enum/HumanoidDisplayDistanceType. When set to viewer, the humanoid’s Name and healthbar will be displayed based on the distance settings of the humanoid viewing them.
Then, the humanoid’s HealthDisplayDistance is set to 0. Setting the property to 0 hides the healthbar completely. It is not displayed at any distance.
Finally, the humanoid’s NameDisplayDistance is set to 100. This means that the humanoid’s name will be visible to other humanoid’s within 100 studs.
This example should work as expected when placed inside a
Script that is a child of the humanoid.