i don’t think this requires any explanation
video of the issue:
code:
local tService = game:GetService("TweenService")
local tweenParameters = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
-- // HUD ELEMENTS
local plrGui = plr.PlayerGui
local screenGui = plrGui:WaitForChild("PlayerHUD")
local main = screenGui:WaitForChild("Main")
local mainHud = main:WaitForChild("HUD")
-- // HEALTH
local healthBar = mainHud:WaitForChild("HealthBar")
local healthAmount = healthBar:WaitForChild("HealthAmount")
local previousHealth = humanoid.Health
-- // STAMINA
local stamina = plr:WaitForChild("Stamina")
local staminaBar = mainHud:WaitForChild("StaminaBar")
local staminaAmount = staminaBar:WaitForChild("StaminaAmount")
-- // CLASS
local classFrame = mainHud:WaitForChild("ClassAbilityFrame")
local classIcon = classFrame:WaitForChild("ClassIcon")
local abilityPercentage = classFrame:WaitForChild("AbilityPercentage")
-- // SOUNDS
local hurtSound = script:WaitForChild("DamageSound")
local lowHealthSound = script:WaitForChild("LowHP")
-- // DAMAGE AND LOW HEALTH FRAMES
local damageTaken = screenGui:WaitForChild("DamageTaken")
local lowHealth = screenGui:WaitForChild("LowHealth")
-- // HEALTH FUNCTION
local function UpdateHealth()
local text = math.floor(humanoid.Health) .. "/" .. humanoid.MaxHealth -- it's something to do with these 3 variables, but idk
local healthPercentage = humanoid.Health / humanoid.MaxHealth
local size = UDim2.new(healthPercentage,0,1,0)
healthAmount.Text = text
local healthBarTween = tService:Create(healthBar, tweenParameters, {Size = size})
healthBarTween:Play()
local damageTakenTween = tService:Create(damageTaken, tweenParameters, {BackgroundTransparency = 1})
local lowHealthTween = tService:Create(lowHealth, tweenParameters, {BackgroundTransparency = 1})
-- // Is health lower than before?
if humanoid.Health < previousHealth then
hurtSound:Play()
damageTaken.BackgroundTransparency = 0.7
damageTakenTween:Play()
end
-- // Is humanoid health critical?
if humanoid.Health <= 30 and humanoid.Health > 0 then
lowHealthSound:Play()
lowHealth.BackgroundTransparency = 0.7
else
lowHealthTween:Play()
end
previousHealth = humanoid.Health
end
-- // STAMINA FUNCTION
local function UpdateStamina()
local text = stamina.Value -- also something to do with these 3, idk!!!
local staminaPercentage = stamina.Value / 100
local size = UDim2.new(staminaPercentage,0,1,0)
staminaAmount.Text = text
local staminaBarTween = tService:Create(staminaBar, tweenParameters, {Size = size})
staminaBarTween:Play()
end
-- // CLASS FUNCTION (TBD)
humanoid:GetPropertyChangedSignal("Health"):Connect(UpdateHealth)
stamina.Changed:Connect(UpdateStamina)
UpdateHealth()
UpdateStamina()
Size of the health bar (in explorer): {0, 315},{0, 25}
Size of the stamina bar (also in explorer): {0, 163},{0, 14}