For my game, my goal is to make a working and functional Health Bar GUI.
However, something in the code doesn’t make the sizing right…
What should happen:
What actually happens:
When the health changes:
Could anyone help? The code is in a LocalScript, which is in a frame.
Code:
wait(0.2)
while true do
local hp = game.Players.LocalPlayer.Character.Humanoid.Health/100
script.Parent:TweenSize((UDim2.new(hp,0,1,0)),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
wait(0.2)
end
Hi My Name Is Kia! I Have Experience In This Problem!
Try This Code :
-- All This Code Must Same With The Parent - Child Name
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local healthbar = script.Parent:WaitForChild("HealthBar") -- The Name Must Same
game:GetService("RunService").RenderStepped:Connect(function()
local humanoid = char:FindFirstChild("Humanoid")
healthbar.GreenFrame.Size = UDim2.new(humanoid.Health/humanoid.MaxHealth,0,1,0)
healthbar.HealthStatus.Text = math.floor(humanoid.Health).."/"..humanoid.MaxHealth
end)