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

trouble putting text between 2 values?

Quickly trying to display the numeric value for a HP bar but I cannot figure out how to put a "/" in between the 2 values.

Here is my code.

local Player = game.Players.LocalPlayer

  

repeat wait() until Player.Character

  

local Humanoid = Player.Character:FindFirstChild("Humanoid")

  

Humanoid.HealthChanged:Connect(function()

script.Parent.Text = "Humanoid.Health / Humandoid.MaxHealth" --I am aware this is wrong, putting the line between "" lets me easily display my intent

end)

obviously I want it to display 100 / 100 and the first number to go down as the player takes damage.

1 answer

✓ Accepted answer

Lua's concatenation operator is ..

script.Parent.Text = Humanoid.Health .. " / " .. Humanoid.MaxHealth

A cleaner looking, or rather a more extendable, approach would be to use the string.format function:

script.Paret.Text = string.format("%d / %d", Humanoid.Health, Humanoid.MaxHealth)

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