How to make a Health Bar in Roblox Studio!!!
Shadow Fox
0:00 / 0:00
How to make a Health Bar in Roblox Studio!!!
24 просмотра · 8 дн. назад
Shadow Fox
35 подписчиков
24 просмотра · 8 дн. назад
How to make a Health Bar in Roblox Studio!!!
Username : Ahmed_2708
Script:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local barFrame = script.Parent
local healthText = barFrame:WaitForChild("HealthText")
local fillFrame = barFrame:WaitForChild("Fill")
local function updateHealthBar(humanoid)
local maxHealth = humanoid.MaxHealth
local currentHealth = humanoid.Health
local ratio = 0
if maxHealth ~= 0 then
ratio = math.clamp(currentHealth / maxHealth, 0, 1)
end
healthText.Text = math.floor(currentHealth) .. " / " .. math.floor(maxHealth)
fillFrame.Size = UDim2.new(ratio, 0, 1, 0)
local red = math.clamp(1 - ratio, 0, 1)
local green = math.clamp(ratio, 0, 1)
fillFrame.BackgroundColor3 = Color3.new(red, green, 0)
end
local function hookCharacter(character)
local humanoid = character:WaitForChild("Humanoid")
updateHealthBar(humanoid)
humanoid.HealthChanged:Connect(function()
updateHealthBar(humanoid)
end)
humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
updateHealthBar(humanoid)
end)
end
if player.Character then
hookCharacter(player.Character)
end
player.CharacterAdded:Connect(hookCharacter)