**What do you want to achieve? This script throws a frame error. I would like the error not to ocurr.
*What is the issue? The script throws this error
HealthStatus is not a valid member of Frame “Players.Darkwulf7777.PlayerGui.HealthBarGui.HealthBar”
Anyone know why this error happens?
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local healthbar = script.Parent:WaitForChild("HealthBar")
game:GetService("RunService").RenderStepped:Connect(function()
local humanoid = char:FindFirstChild("Humanoid")
healthbar.GreenFrame.Size = UDim2.new(humanoid.Health/humanoid.MaxHealth,0,1,0)
healthbar.HealthStatus.Text = math.floor(humanoid.Health).."/"..humanoid.MaxHealth
end)
I think the issue is that it’s still trying to load everything inside your PlayerGui, even though you called WaitForChild() on your HealthBar it’s still trying to load the rest of the UI Objects
You should also used a HealthChanged Event instead of a RenderStepped, that’d would way easier
Try this:
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local healthbar = script.Parent:WaitForChild("HealthBar")
local HealthStatus = healthbar:WaitForChild("HealthStatus")
local GreenFrame = healthbar:WaitForChild("GreenFrame")
Humanoid.HealthChanged:Connect(function(NewHealth)
GreenFrame.Size = UDim2.new(NewHealth/Humanoid.MaxHealth,0,1,0)
HealthStatus.Text = math.floor(NewHealth).."/"..Humanoid.MaxHealth
end)
StarterGui gets replicated to the Player and becomes PlayerGui. You need to change your code to cater for this. Run the game up in Studio and look at the Player and it’s sub-items, where you will see the full structure.