local healthNUM = script.Parent
local pl = game.Players.LocalPlayer
local char = pl.Character
local hum = char.Parent:FindFirstChild("Humanoid")
hum.HealthChanged:Connect(function(Damage)
script.Parent.Size = UDim2.new(Damage / hum.MaxHealth, 0,1,0)
end)
local function Number()
healthNUM.Text = tostring (hum.Health) .."/".. tostring (hum.MaxHealth)
end
Number()
hum.HealthChanged:Connect(Number())
Try this, if it doesnt work, post the output error here, so i can know what exactly doesnt work
I didn’t resift a error but the script still doesn’t work
Replace
local healthNUM = script.Parent
with
local healthNUM = script.Parent.TextLabel
I see a LOT of problems with this code.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
local HealthBar = script.Parent
local HealthNumber = path.to.the.textlabel
HealthNumber.Text = tostring(Humanoid.Health) .. "/" .. tostring(Humanoid.MaxHealth)
HealthBar.Size = UDim2.new(Humanoid.Health / Humanoid.MaxHealth, 0, 1, 0)
Humanoid.HealthChanged:Connect(function(Health)
HealthBar.Size = UDim2.new(Health/ Humanoid.MaxHealth, 0, 1, 0)
end)
Put this in the healthbar frame as a localscript, and also dont forget to enable ResetOnSpawn on the gui.
Tell me if something is wrong, also reset and see if it works then.
2 Likes
if you put the textlabel it will be equal to unknow
What? What do you mean unknown
You cant change a text of a frame, because a frame doesnt have a text
Your textlabel.text is the text
You should really learn the basics of scripting.
Then he should put the billboardgui in StarterGui, and set the adornee
this is not for player health bar this for the npc
doesnt matter, still try what i said
but still the script for the player is helpful
1 Like
thx you all that help me it work thx
kylerzong
(kylerzong)
#35
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Gui = Instance.new("ScreenGui")
Gui.Name = "HoverHealthBar"
Gui.Parent = Player.PlayerGui
local function ParentWatchdog(Parent)
if Gui.Parent == nil then
Gui = Gui:Clone()
Gui.Parent = Player.PlayerGui
Gui:GetPropertyChangedSignal("Parent"):Connect(function()
ParentWatchdog(Gui)
end)
end
end
Gui:GetPropertyChangedSignal("Parent"):Connect(function()
ParentWatchdog(Gui)
end)
local MainFrame = Instance.new("Frame")
MainFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
MainFrame.Size = UDim2.fromOffset(100, 20)
MainFrame.Visible = false
MainFrame.Name = "MainFrame"
MainFrame.Parent = Gui
local BackgroundFrame = Instance.new("Frame")
BackgroundFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
BackgroundFrame.Size = UDim2.fromScale(1, 1)
BackgroundFrame.Name = "BackgroundFrame"
BackgroundFrame.Parent = MainFrame
local HealthFrame = Instance.new("Frame")
HealthFrame.BackgroundColor3 = Color3.fromRGB(0, 250, 0)
HealthFrame.Size = UDim2.fromScale(1, 1)
HealthFrame.Name = "HealthFrame"
HealthFrame.Parent = MainFrame
local Text = Instance.new("TextLabel")
Text.BackgroundTransparency = 1
Text.Size = UDim2.fromScale(.5, 1)
Text.Position = UDim2.fromScale(.25, 0)
Text.Parent = MainFrame
Text.TextColor3 = Color3.fromRGB(255, 0, 0)
Text.Font = Enum.Font.Oswald
Text.Name = "Text"
Text.TextSize = 20
local function UpdateGui()
if not Gui:FindFirstChild("MainFrame") then return false end
if not Mouse.Target then Gui.MainFrame.Visible = false return false end
local Parent = Mouse.Target.Parent
if Parent == workspace then Gui.MainFrame.Visible = false return false end
local Humanoid = Parent:FindFirstChildOfClass("Humanoid")
if not Humanoid then Gui.MainFrame.Visible = false return false end
Gui.MainFrame.Position = UDim2.fromOffset(Mouse.X - MainFrame.Size.X.Offset/2, Mouse.Y - (Gui.MainFrame.Size.Y.Offset+20))
Gui.MainFrame.HealthFrame.Size = UDim2.fromScale(Humanoid.Health/Humanoid.MaxHealth, 1)
Gui.MainFrame.Visible = true
if Humanoid.Health == 0 then
Gui.MainFrame["Text"].Text = "DEAD"
else
Gui.MainFrame["Text"].Text = tostring(Humanoid.Health).. " / "..tostring(Humanoid.MaxHealth)
end
return true
end
local LiveThread = false
Mouse.Move:Connect(function()
if LiveThread then return end
if UpdateGui() then
coroutine.wrap(function()
LiveThread = true
repeat
wait()
until
not UpdateGui()
LiveThread = false
end)()
end
end)
For a ScreenGui healthbar you can try this script in StarterPlayerScripts
1 Like