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

Can't concatenate text?

So I've been working on a health GUI and it all works nicely, the bar scales and everything, but the text just does not update. I'm not sure if it's an error with concatenation or what, but it just doesn't work. Thanks!

maxHealth = player.Bin.MaxHealth
health = maxHealth

character.Humanoid.MaxHealth = maxHealth.Value
character.Humanoid.Health = health.Value


character.Humanoid.HealthChanged:connect(function()
	hpBar:TweenSize(UDim2.new(character.Humanoid.Health/character.Humanoid.MaxHealth,0,1,0),"Out","Quad",0.5)
	hpLabel.Text = ""..math.floor(health.Value)..""
	if character.Humanoid.Health == 0 then
		hpBar:TweenSize(UDim2.new(0,0,1,0),"Out","Quad",0.5)
		hpLabel.Text = ""..math.floor(health.Value)..""
	end
end)

1 answer

✓ Accepted answer

Try just using the tostring function in Lua

If we have an int value,

local int = 55

We can make this into a string using,

local int = 55
local string = tostring(int)

Your code,

Hopefully this will work,

maxHealth = player.Bin.MaxHealth
health = maxHealth

character.Humanoid.MaxHealth = maxHealth.Value
character.Humanoid.Health = health.Value


character.Humanoid.HealthChanged:connect(function()
    hpBar:TweenSize(UDim2.new(character.Humanoid.Health/character.Humanoid.MaxHealth,0,1,0),"Out","Quad",0.5)
    hpLabel.Text = tostring(math.floor(health.Value))
    if character.Humanoid.Health == 0 then
        hpBar:TweenSize(UDim2.new(0,0,1,0),"Out","Quad",0.5)
        hpLabel.Text = tostring(math.floor(health.Value))
    end
end)

I hope I helped!

Good Luck!

3 comments

1

worked perfectly, thanks

0

np

0

That's odd. Usually numbers automatically convert to strings when concatenated, in Lua.

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