Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make the custom health gui decreases when the player health decreases too?

Asked by 7 years ago
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local Humanoid = player.Character:WaitForChild("Humanoid")
local HealthMath = Humanoid.Health / (Humanoid.MaxHealth)

script.Parent:TweenSize(UDim2.new(HealthMath, 0, 1, 0), "Out", "Sine", .5)

Humanoid.HealthChanged:connect(function()
    local HealthMath = Humanoid.Health / (Humanoid.MaxHealth)
    script.Parent:TweenSize(UDim2.new(HealthMath, 0, 1, 0), "Out", "Sine", .5)
end)

So when I take a slightly damage .. The gui overlay do decreases but when it is instant damage the gui overlay just stuck at the previous health. For example , current health now is 100 and took 50 damage then the gui overlay decreases to 50 but when it take sudden/instant death for example by a rocket or explosion current health now 0 but the gui still showing 50.

0
Change HealthMath to "HealthMath = (100/Humanoid.MaxHealth)*Humanoid.health TheHospitalDev 1134 — 7y
0
It kinda works but for some reason my health gui becomes longer. From https://ibb.co/hTC9o5 to https://ibb.co/n0jpo5 xiFrosty 13 — 7y
0
You're putting HealthMath in the Scale.X field of UDim2, not the Offset.X, so a value of 100 means 100 times the width of the parent GUI. Use UDim2.new(0, HealthMath, 1, 0) instead. duckwit 1404 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Local script Put the local script inside a frame.

wait()

local Player = game:GetService'Players'.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Human = Character:WaitForChild("Humanoid")

local HealthFrame = script.Parent

Human.HealthChanged:connect(function(Health)
    HealthFrame.Size = UDim2.new(Health/Human.MaxHealth,0,1,0)
end)

Here is a Pic http://imgur.com/TdqTxfv

0
Thank you very much !! :D Need to re-script meh script xD xiFrosty 13 — 7y
0
np SamthekidRSsl 58 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Use a repeat function to get the player's max health and health. Have it update every 0.05 seconds. That way it will update it.

Answer this question