How do I hide a Player's Humanoid's Name/Health

I’m pretty new to lua but I’m trying to disable/hide the Name and Health of any Player’s in a game - (this is because I have a custom GUI that will replace them)

Is there any way I can do this? If so, how?

16 Likes

The Humanoid has a property called DisplayDistanceType. If you set it to:
Enum.HumanoidDisplayDistanceType.None
Then health nor name is visible.

This can be done quite simply with a script located in serverscriptservice:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
    end)
end)

Please indent accordingly :slight_smile:

59 Likes

Thank you, and if you didn’t already know you can click this button to put your code in a code block:

image

3 Likes

You can also make code blocks by placing three grave marks (```) together at the start and then three more at the end.

code
2 Likes
game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").NameDisplayDistance = 0
	end)
end)

Can someone tell me why this server script is not working when I test in-game?

3 Likes

Is there any code before it that is preventing it from continuing, such as a while do loop that never ends? Is the script this code is running in disabled? That code looks to me like it would work.

It’s on it’s own inside a server script.

Did you check if the script is disabled (I’ve disabled a script before and forgot to re-enable it, took me a while to figure out the issue)? If it isn’t disabled, where is it parented to?

The script is not disabled, it’s inside ServerScriptService - It’s fine, not needed, thanks anyway

I just tried the code and it worked perfectly fine for me… That’s interesting.

It should look like this:
@Thundermaker300

game:GetService("Players").PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Char)
        wait(1)
		Char:FindFirstChild("Humanoid").NameDisplayDistance = Enum.HumanoidDisplayDistanceType.None
	end)
end)

According to the wiki, NameDisplayDistance is a float, not an Enum. You’re thinking of HumanoidDisplayDistanceType. Like I said, his code worked fine when I tried it in studio, that’s odd it’s not working for him.

Perhaps he’s trying it server side, I added the wait on purpose.

Here, this is what I use. It guarantees you will get the players’ character. Also, why not just set DisplayDistanceType?

game.Workspace.ChildAdded:connect(function(c) --Just check whenever something is added to workspace.
	if game.Players:GetPlayerFromCharacter(c) and c:FindFirstChild("Humanoid") then --Check if it is a player's character and make sure it has a humanoid.
		c.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None --Set the propety.
	end
end)
2 Likes

Everyone else’s Code works quite fine, except the health displays when damaged. So I’ll leave my two cents here and hopefully your problem will be solved.

game:GetService("Players").PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		if hum then
			hum.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
			hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		end
	end)
end)
7 Likes

Thanks for the help everyone.

FWIW, I’ve always just done this. I didn’t even know about DisplayDistanceType! No code required.
namedisplaydistance

39 Likes

You can go to StarterPlayers in the Explorer, then set NameDisplayDistance and HealthDisplayDistance to 0.

Did you not see its a 2 year old thread?

…No. No I did not. Thank you. They never set anything as a solution, though. Thank you.

3 Likes