local Bar = script.Parent:WaitForChild("Bar")
local HP = script.Parent:WaitForChild("HP")
local player = game.Players.LocalPlayer
repeat wait(1) until player.Character
local connection_health
local connection_max_health
local character = player.Character
local function update()
local humanoid = character:WaitForChild("Humanoid")
Bar:TweenSize(UDim2.new(humanoid.Health / humanoid.MaxHealth, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quint, 1, true)
HP.Text = humanoid.Health .. "/" .. humanoid.MaxHealth .. " HP "
end
local function setConnections()
local humanoid = character:WaitForChild("Humanoid")
connection_health = humanoid:GetPropertyChangeSignal("Health"):Connect(update)
connection_max_health = humanoid:GetPropertyChangeSignal("MaxHealth"):Connect(update)
update()
end
player.CharacterAdded:Connect(function(char)
character = char
if connection_health then connection_health:Disconnect() end
if connection_max_health then connection_max_health:Disconnect() end
setConnections()
end)
setConnections()
don’t put :WaitForChild in the function
it didnt work
am i supposed to remove all of it?
local humanoid = character:WaitForChild(“Humanoid”)
or what do i change in it
you listed the function, but forgot the ().
it should be
connection_health = humanoid:GetPropertyChangeSignal(“Health”):Connect(update())
connection_max_health = humanoid:GetPropertyChangeSignal(“MaxHealth”):Connect(update())
Because it is calling the function. and when you call a function, even if empty, you still must mention “hey this is a function!” by having the ()
the ui still no work i dk if i am missing something
You state that things are not working as you expect.
Can you put some prints in to confirm the process flows as you expect and that any variables the process depends on has a value you expect at that point in the flow.
This method gives you an execution road map of what is happening so you can determine where things are gong wrong or not happening.
Please give it a go.
how i put that in to my script, do i do something like if true print(“it works”)
There’s a few typos here and there:
Use 2 dots instead of 3
--HP.Text = humanoid.Health … “/” … humanoid.MaxHealth … " HP "
HP.Text = humanoid.Health .. "/" .. humanoid.MaxHealth .. " HP "
Misspelled GetPropertyChangedSignal (Change → Changed)
--connection_health = humanoid:GetPropertyChangeSignal(“Health”):Connect(update)
--connection_max_health = humanoid:GetPropertyChangeSignal(“MaxHealth”):Connect(update)
connection_health = humanoid:GetPropertyChangedSignal("Health"):Connect(update)
connection_max_health = humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(update)
I strongly recommend making a connection to the humanoid’s HealthChanged event rather than having two :GetPropertyChangedSignal()
connections on the health properties, though they pretty much will have the same functionality.
By the way,
this is wrong. The function’s parentheses are not supposed to be included when it is connected to an event. An error will show up saying that the passed value was not a function.
oh crap
I thought I tested that statement before I made it, sorry.
the ui still no change, thx for helping tho, i think i might have to recreate the ui again because of the ui aspect ratio thing
could you post your code in proper syntax? put 3 ` at the beginning and end of your code to create a code block
ok i changed it, it has scroll thing now
It seems in your screenshot, “HP” is under Bar. Try setting HP to
local HP = Bar.HP
Along with my previous post
i did this,
local HP = Bar.HP.script.Parent:WaitForChild("HP")
but the ui will not change
no, it should just be
local HP = Bar.HP