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:
What I want to achieve:
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)
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?
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.
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.
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