i have no idea how to do health gui script can someone help me?
Set the X size of the GuiObject using health / max health (of the player) use Tween Service to make it smooth, make sure the anchor point is 0.5,0
can you give me example ?
i have no idea how math work i’m dumb
Here is some code, it might help:
local Player = game:GetService("Players").LocalPlayer
local RS = game:GetService("RunService")
local HealthBar = script.Parent
RS.RenderStepped:Connect(function()
local HealthPercentage = Player.Character.Humanoid.Health / Player.Character.Humanoid.MaxHealth
Bar.Size = UDim2.new(0,HealthPercentage,1,0)
end)
Let me know if you have any problems with this
(It’s a local script in the bar)
No it not work i think it look very weird i mean the script
Try and make the UDim2 value UDim2.new(0,HealthPercentage,0,1)
Pretty new to gui work myself.
In a local script inside the bar.
Check miss-spelling since I wrote on phone.
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
.2 --time
)
local bar = script.Parent
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdde:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(function()
tweenService:Create(bar,
tweenInfo,
{
Size = UDim2.fromScale(humanoid.Health / humanoid.MaxHealth, 1)
}):Play()
end)
Don’t forget to set the bar AnchorPoint (property) to 0.5, 1
i think i do something wrong
What is the health bar’s maximum size?
Code posted in this thread doesn’t work well because Health isn’t a descendant of HealthBg. Move Health to HealthBg, set it’s default size to 1,0,1,0 position to 0,0,0.5,0 and anchor point to 0,0.5 and code above will work.