Trying to update text in the label (script's parent) based on health, it makes the text the player's health at first but doesn't update, I tried making a loop but.... yeah, nothing.
local plr = game.Players.LocalPlayer local character = plr.Character or plr.CharacterAdded:Wait() local noid = character:WaitForChild("Humanoid", 10) local health = noid.Health local label = script.Parent script.Parent.Text = ""..health.."" while noid.Health < 100 do wait(.1) if noid.Health < 100 then label.Text = ""..health.."" end end
I'd really love to receive educational answers! Ty!
That because you not update health
variable!
you can do 2 ways
1.) Update "health" variable
2.) Use Text = character.Humanoid.Health
And if you want to make loop, do this..
while true do --script... wait() end
Here is example
local plr = game.Players.LocalPlayer local character = plr.Character or plr.CharacterAdded:Wait() repeat wait() until character:FindFirstChild("Humanoid") local label = script.Parent script.Parent.Text = ""..character.Humanoid.Health.."" while true do label.Text = character.Humanoid.Health wait() end
But the best way is GetPropertyChangedSignal("Property Name")
Here is example
local plr = game.Players.LocalPlayer local character = plr.Character or plr.CharacterAdded:Wait() repeat wait() until character:FindFirstChild("Humanoid") local label = script.Parent script.Parent.Text = ""..character.Humanoid.Health.."" character.Humanoid.Health:GetPropertyChangedSignal("Health"):Connect(function() label.Text = character.Humanoid.Health end)
local plr = game.Players.LocalPlayer local character = plr.Character or plr.CharacterAdded:Wait() local noid = character:WaitForChild("Humanoid") local health = noid.Health local label = script.Parent script.Parent.Text = ""..health.."" while wait(.1) do if noid.Health < 100 then label.Text = ""..health.."" end end
Using a while true do loop is not needed. Try updating it only when there is a change. This can be done using the changed function.
Second of all, you set the variable 'health' to the humanoids health value. Therefore, it will always be the same number
local plr = game:GetService("Players").LocalPlayer local Character = plr.Character or plr.CharacterAdded:wait() local noid = Character:FindFirstChildOfClass("Humanoid") local label = script.Parent script.Parent.Text = ""..noid.Health noid.Changed:Connect(function() if noid.Health < 100 then label.Text = ""..noid.Health else label.Text = "100" end end)