How do you make the Health round to nearest one in this script? This script is in an NPC. The health regeneration causes the health to be in a decimal place, but I want it to show only the whole number. In other words, I want the NPC's name to display as a whole number, but his health is still generating in decimals.
1 | while true do |
2 | script.Parent.Name = "Name Lv 1 " .. script.Parent.Humanoid.Health .. "/" .. script.Parent.Humanoid.MaxHealth |
3 | wait() |
4 | end |
You can use math.floor(value)
to round it, cutting of the decimal part. If you want proper rounding, you can use this:
1 | local function round(value) |
2 | return math.floor(value+ 0.5 ) |
3 | end |
4 | print (round( 1 )) --> 1 |
5 | print (round( 1.2 )) --> 1 |
6 | print (round( 1.4 )) --> 1 |
7 | print (round( 1.6 )) --> 2 |
8 | print (round( 1.8 )) --> 2 |
9 | print (round( 2 )) --> 2 |
Marked as Duplicate by User#5423, gskw, and Discern
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?