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.
while true do script.Parent.Name = "Name Lv 1 " .. script.Parent.Humanoid.Health .. "/" .. script.Parent.Humanoid.MaxHealth wait() end
You can use math.floor(value)
to round it, cutting of the decimal part. If you want proper rounding, you can use this:
local function round(value) return math.floor(value+0.5) end print(round(1)) --> 1 print(round(1.2)) --> 1 print(round(1.4)) --> 1 print(round(1.6)) --> 2 print(round(1.8)) --> 2 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?