Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

3 comments

0

Change HealthMath to "HealthMath = (100/Humanoid.MaxHealth)*Humanoid.health

0

It kinda works but for some reason my health gui becomes longer. From https://ibb.co/hTC9o5 to https://ibb.co/n0jpo5

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.

2 answers

✓ Accepted answer

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

2 comments

0

Thank you very much !! :D Need to re-script meh script xD

0

np

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.