How would you make a local player’s overhead health bar only show to other players? When a player joins the game, their health bar is not visible to them, but it is visible to other players.
With my script, the health bar isn’t visible to anyone, meaning players don’t know when they are about to die. The health bar is a regular script and is located within the starter player scripts with a billboardgui as the overhead health bar.
I tried making it a local script, putting it into starter character scripts instead, but no positive results came back.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
script:
> local Players = game:GetService("Players")
>
> local function isLocalPlayer(player)
> return player == Players.LocalPlayer
> end
>
> local char = script.Parent
> local healthGui = script.HealthGui
> local humanoid = char:WaitForChild("Humanoid")
>
> healthGui.Parent = char.Head
>
> humanoid:GetPropertyChangedSignal("Health"):Connect(function()
> local healthChange = humanoid.Health / humanoid.MaxHealth
> local healthColor = Color3.fromRGB(255, 0, 0):Lerp(Color3.fromRGB(60, 255, 0), healthChange)
>
> healthGui.Health.Meter:TweenSize(UDim2.new(healthChange, 0, 1, 0), "In", "Linear", 1)
> healthGui.Health.Meter.BackgroundColor3 = healthColor
>
> -- Check if the player is not the local player before showing the health bar
> if not isLocalPlayer(Players.GetPlayerFromCharacter(char)) then
> healthGui.Visible = true
> else
> healthGui.Visible = false
> end
> end)
I’ll be grateful if you could help me out, and I hope you have a lovely happy holiday!
When you do things on the client, it doesn’t replicate to the server (and won’t replicate to other players). Add a script in ServerScriptService and add your nametags there.
Alright, I put a local script in StarterPlayerScript with the health billboard and a script in serverscriptservice. and still no sign of working… thanks for commenting at least!
script inside serverscriptservice:
local Players = game:GetService("Players")
local function isLocalPlayer(player, playerToHideFrom)
return player == playerToHideFrom
end
local function setupHealthGui(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local healthGui = Instance.new("Folder")
healthGui.Name = "HealthGui"
healthGui.Parent = character.Head
local meter = Instance.new("Frame")
meter.Name = "Meter"
meter.Size = UDim2.new(1, 0, 1, 0)
meter.Parent = healthGui
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
local healthChange = humanoid.Health / humanoid.MaxHealth
local healthColor = Color3.fromRGB(255, 0, 0):Lerp(Color3.fromRGB(60, 255, 0), healthChange)
meter:TweenSize(UDim2.new(healthChange, 0, 1, 0), "In", "Linear", 1)
meter.BackgroundColor3 = healthColor
-- Check if the player is not the local player before showing the health bar
if not isLocalPlayer(player, playerToHideFrom) then
healthGui.Visible = true
else
healthGui.Visible = false
end
end)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
setupHealthGui(player)
end)
end)
Local script inside of StarterPlayerScripts:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
end)
end)