Having trouble trying to make a over-head health bar that displays others health but not my own

Hey. I’m trying to make a overhead healthbar/username billboardgui so it displays the players username and health above their head but I want it to only show the other players health for me instead of my own. how can I make it so that I can see the other players health and they can see mine but we cant see our own health? I don’t really have an idea of how I can fix/achieve this.

What’s happening:
image

What I want to achieve:
whatiwanttoachieve

I have tried to look around on the forums but haven’t had any luck of finding any possible solutions.

The script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local UserInfoUI = ReplicatedStorage:WaitForChild("PlayerInfoUI")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local UserInfoUIClone = UserInfoUI:Clone()
		UserInfoUIClone.PlayerUsername.Text = Player.Name
		UserInfoUIClone.Parent = Character:WaitForChild("Head")
		UserInfoUIClone.Adornee = Character:WaitForChild("Head")
		
		if UserInfoUIClone.PlayerUsername.Text == Player.Name then
			UserInfoUIClone.Background.Visible = false
		end
	end)
end)
4 Likes

Your script looks great but you have trouble comparing the local player’s name with the name on the UI element

if Player == Players.LocalPlayer then
   UserInfoUIClone.Enabled = false
end
5 Likes

Yeah, also sorry for not completely specifying, Background is the Health Bar which is a Frame that has everything needed for the Health Bar. Would I still use Background.Visible = false or something different?

4 Likes

If you want to hide only the HP bar, yes, you should use UserInfoUIClone.Background.Visible = false.
If you want to hide whole thing with username and stuff, you should use UserInfoUIClone.Enabled = false.

3 Likes

Alright thank you, I’ll try that.

3 Likes

Let me know if it helps and don’t forget to mark the solution.

3 Likes

I just tested, it still shows my health bar and the other players.

2 Likes

Are you viewing it from the server-side or like playing it with your actual character?

2 Likes

I’m team testing it with my actual character.

2 Likes

Try this:

if Player == Players.LocalPlayer then
    UserInfoUIClone.Background.Visible = false
else
    UserInfoUIClone.Background.Visible = true
end
1 Like

It’s still showing my health bar and the other players.

1 Like

Can you provide screenshots of the UI children and what’s showing?

1 Like

image
This is inside of my characters head.

1 Like

HealthBarManager is what functions the healthbar, not the PlayerInfoUI. I also forgot to mention the script that we are working with right now is in ServerScriptService and is a server script.

1 Like

That explains a lot, I’ll replicate your setup and test it in my environment, gimme sec

1 Like

Alright. Sorry for any confusions lol.

1 Like

Okay so here is the solution:
Place this in your ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local UserInfoUI = ReplicatedStorage:WaitForChild("PlayerInfoUI")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local UserInfoUIClone = UserInfoUI:Clone()
		--UserInfoUIClone.Name
		UserInfoUIClone.Parent = Character:WaitForChild("Head")
		UserInfoUIClone.Adornee = Character:WaitForChild("Head")
	end)
end)

And this in StarterCharacterScript (This should be LocalScript)

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local function onCharacterAdded(character)
	local head = character:WaitForChild("Head")
	local playerInfoUI = head:WaitForChild("PlayerInfoUI")

	if playerInfoUI then
		if playerInfoUI:FindFirstChild("Background") then
			playerInfoUI.Background.Visible = false
		end
	end
end

LocalPlayer.CharacterAdded:Connect(onCharacterAdded)
if LocalPlayer.Character then
	onCharacterAdded(LocalPlayer.Character)
end

Let me know if this helps

1 Like

This works. I just had to add in the line for the Username text but this does what I want it to. Thanks for the help!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.