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

Why is my custom health gui not working and showing no error?

There is no error what so ever, I tried putting the(0, humanoid.Health/humanoid.MaxHealth , 0, 1)as (humanoid.Health/humanoid.MaxHealth , 0, 1, 0) still no change. I just don't get why.

http://imgur.com/jzygRCy

local startgui = game:GetService("StarterGui")

startgui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

--Player stuff
local player = game.Players.LocalPlayer
local char = player:WaitForChild("Character")
local humanoid = char:WaitForChild("Humanoid")

--Gui Stuff
local gui = script.Parent
local ground = gui.BackGround
local thing = ground.Health
local health = thing.Frame



humanoid.HealthChanged:connect(function(Health)
	wait(0.1)
	health.TextLabel.Text = humanoid.Health.."/100"
	health:TweenSize(UDim2.new(Health/humanoid.MaxHealth, 0 , 1, 0), "Out", Enum.EasingStyle.Linear, 0.1)
end)

	

4 comments

0

Please put the code in a "Code Block"

0

Dont know how

0

Click on the Lua logo icon when writing a question or answer. It will add two tilde lines. Text writen between the two lines, will appear in a code block.

0

First of all, is it a local script? SerCoreGuiEnabled, along with game.Players.LocalPlayer only work in localscripts

1 answer

✓ Accepted answer

##Problem

You're waiting for something that will never exist, Character. Character is property rather than an object in Player.


##Solution

Remove it. You may be concerned that character may not exist when the player respawns, you could simply place a repeat loop until the character exists. This mistake is subtle but may show up after some time if the WaitForChild takes too long to pass.


##Final Script

local startgui = game:GetService("StarterGui")

startgui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

--Player stuff
local player = game.Players.LocalPlayer
repeat wait() until player.Character ~= nil --Just keep waiting until the character doesn't equal "doesn't exist" (nil).
local humanoid = player.Character:WaitForChild("Humanoid") --Since we got rid of the Character variable, we just changed char to player.Character here.

--Gui Stuff
local gui = script.Parent
local ground = gui.BackGround
local thing = ground.Health
local health = thing.Frame



humanoid.HealthChanged:connect(function(Health)
    wait(0.1)
    health.TextLabel.Text = humanoid.Health.."/100"
    health:TweenSize(UDim2.new(Health/humanoid.MaxHealth, 0 , 1, 0), "Out", Enum.EasingStyle.Linear, 0.1)
end)

######Hopefully, this answered your question. If it did, do not forget to hit the accept answer button. If you have any questions, feel free to ask in the comments.

2 comments

0

OMG THANK YOU SO MUCH. I will remember that tip next time!

0

That "~= nil" check is redundant.

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