The three highlighted sections pieces are part of the Health Bar.
I dont really see what the exact purpose is with the index keys for UDim2
stuff, Im not sure why you just dont randomize it at all.
You appear to me missing the 4th Argument within UDim2.new()
, which is the yOffset
, If you are only using the Scale, you should be using Udim2.fromScale()
, Like this:
UDim2.fromScale(.00135, 1)
Take a photo of the explorer in the playergui during a test. Maybe it is being parented to something else or being destroyed.
also, you forgot to add .Text
, not sure if this is causing the issue, but it might be so go fix that:
game.Players.LocalPlayer.PlayerGui.ScreenGui.UpperBars.HealthDisplay.Text = i.."/100"
not in his.
it is turning health display to the string with this line.
Yeah, i just saw what he did, my bad…
Try this code:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait() --The code will keep waiting on this line if the player's character hasn't been added or finished loading into the server.
local Humanoid = Character:WaitForChild("Humanoid") -- Referencing and getting the character's humanoid.
local PlayerGUI = LocalPlayer:WaitForChild("PlayerGui")
Humanoid.HealthChanged:Connect(function(CurrentHealth))
PlayerGUI.ScreenGui.UpperBars.Health.LiveHealth.Size = UDim2.new(CurrentHealth/Humanoid.MaxHealth, 0,1,0) -- Tweens the size of the bar depending on how much hp the player has
PlayerGUI.ScreenGui.UpperBars.HealthDisplay.Text = math.floor(Humanoid.Health).."/"..(Humanoid.MaxHealth)
end)
Thank you so much! I feel stupid now knowing it could’ve been done this way.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.