Im trying to make it so the text is the same as the health and it works, but i found out that there are decimals and i dont know how to fix that, can some1 help me this is my script so far
local hi = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
script.Parent.Text = hi.Humanoid.Health
game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Humanoid.HealthChanged:connect(function()
script.Parent.Text = hi.Humanoid.Health
end)
01 | local hi = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name) |
02 | script.Parent.Text = hi.Humanoid.Health |
03 | game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Humanoid.HealthChanged:connect( function () |
04 | local roundednum = Instance.new( 'IntValue' ) -- a Interger Value will only show up as a number, not decimals |
05 | roundednum.Value = hi.Humanoid.Health -- change the value of the Interger Value, and it will round it up |
06 | wait(. 001 ) |
07 | script.Parent.Text = roundednum.Value -- changes the text |
08 | hi.Humanoid.Health = roundednum.Value -- (you can remove this if you want) it will change the player's health without decimals |
09 | roundednum:remove() -- clears the rounded number |
10 | end ) |
You can do math.floor
or math.ceil
. math.floor
rounds down, and math.ceil
rounds up.
Here is a example of what math.floor
does.
1 | local heath = 48.7917 |
2 | print (math.floor(health)) --This will print 48. |
This is a example of what math.ceil
does.
1 | local health = 63.2539 |
2 | print (math.ceil(health)) --This will print 64. |
Also, when writing scripts on this website, use a code block.