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

I'm getting this malformed number error. How do I fix that?

What is in the title..

local health = player.Character.Humanoid.Health
script.Parent.Size = UDim2.new(0.health*3.63,0,2.3,0) 

Offset wasn't doing very well so I changed the values to scale. But when I try to add a 0.health it gives me the error saying: Malformed number How do I fix that?

Thanks!

2 answers

✓ Accepted answer

Hmm, you're getting the error because you used 0.health which is not a real number.

Try this:

local health = player.Character.Humanoid.Health
local maxHealth = player.Character.Humanoid.MaxHealth
script.Parent.Size = UDim2.new((health / maxHealth)*3.63,0,2.3,0) 

4 comments

0

BOI

0

You could also do (health / 100) * 3.63. Hope this helps.

0

Or, tonumber('0.'..health)*3.63

0

Just edited it, assuming you're trying to set the size of the gui object to the percentage of what the player's health is.

UDim2.new(0.health*3.63,0,2.3,0) is wrong. You better use UDim2.new(health/(10 ^ tonumber(#tostring(health)))*3.63, 0, 2.3, 0)

3 comments

0

health is a number value though, so why the # operator?

0

You can't use # on a number.

0

alright imma edit this

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