Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can't concatenate text?

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
1
Answered by 7 years ago

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!

1
worked perfectly, thanks jakei181 60 — 7y
0
np User#11440 120 — 7y
0
That's odd. Usually numbers automatically convert to strings when concatenated, in Lua. Link150 1355 — 7y
Ad

Answer this question