Displaying team-mate names and health through walls with default name/health

I want to display the names and health of my team-mates by using the default name/health system. I have tried some code and it does not work, the player’s names and health do not show from very far away, it uses the default display distance and type. Any help would be appreciated.

--// SERVICES

local playersService		= game:GetService('Players')
local localPlayer			= playersService.LocalPlayer

for playerNum,indivPlayer in pairs(game.Players:GetChildren()) do
	local indivCharacter = indivPlayer.Character
	local indivHumanoid = indivCharacter:FindFirstChild("Humanoid")
	
	if localPlayer.TeamColor == BrickColor.new('Bright red') or localPlayer.TeamColor == BrickColor.new('Medium stone grey') then
		if (indivPlayer.TeamColor == BrickColor.new('Bright red') or indivPlayer.TeamColor == BrickColor.new('Medium stone grey')) then
			indivHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
			indivHumanoid.HealthDisplayDistance = math.huge
			indivHumanoid.NameDisplayDistance = math.huge
			indivHumanoid.NameOcclusion = Enum.NameOcclusion.EnemyOcclusion
			print ('Show me names and health of anyone on EITHER of these teams')
		end
	elseif localPlayer.TeamColor == BrickColor.new('Brown') then
		if indivPlayer.TeamColor == BrickColor.new('Brown') then
			indivHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
			indivHumanoid.HealthDisplayDistance = math.huge
			indivHumanoid.NameDisplayDistance = math.huge
			indivHumanoid.NameOcclusion = Enum.NameOcclusion.EnemyOcclusion
			print ('Show me names and health of anyone on this team')
		end
	elseif localPlayer.TeamColor == BrickColor.new('Really black') then
		if indivPlayer.TeamColor == BrickColor.new('Really black') then
			indivHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
			indivHumanoid.HealthDisplayDistance = math.huge
			indivHumanoid.NameDisplayDistance = math.huge
			indivHumanoid.NameOcclusion = Enum.NameOcclusion.EnemyOcclusion
			print ('Show me names and health of anyone on this team')
		end
	end
end

This is easy to fix. You do not have to find what team the player is, because “EnemyOcclusion” only hides enemies, not teammates. Just set Humanoid.NameOcculusion to EnemyOcclusion with a script, and set the “HealthDisplayDistance” and “NameDisplayDistance” in the “StarterPlayer” to a very extremely long number.

Here’s a script I made that you put in “ServerScriptService” that should fix it.
I have not tested this with someone, but it should work.

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		wait(.001)
		char:WaitForChild('Humanoid').NameOcclusion=Enum.NameOcclusion.EnemyOcclusion
		char:WaitForChild('Humanoid').HealthDisplayDistance=999999*999999
		char:WaitForChild('Humanoid').NameDisplayDistance=999999*999999
	end)
end)

That’s fine but the issue is, I have two separate teams in one place, that are considered allies and fight for one objective, I want people from either of those teams to be able to see the other teams names/health, and they are the Bright red and Medium stone grey TeamColours.

Honestly you would be better off programming a custom healthbar billboard UI, as billboard UIs allow you to see them through walls.

This would also give you more control over which ones to show through walls, and which ones to hide behind walls.

6 Likes

Already made one, just wanted to see whether normal names and health would look better. Thanks anyway guys.

2 Likes