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

How to make health round to nearest whole number?

Asked by 3 years ago
Edited 3 years ago

I am making a Half-Life 2 styled health GUI and it works except it will display decimals. So instead of showing 47 it shows something like 47.12515. Does anyone know how I could fix this?

Here is my script:

`local player = script.Parent.Parent.Parent.Parent.Parent

while true do hel = player.Character.Humanoid.Health if hel <= 25 then script.Parent.Text = hel script.Parent.BackgroundColor = BrickColor.new ("Bright red") else script.Parent.Text = hel script.Parent.BackgroundColor = BrickColor.new ("Bright green") end wait() end`

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local player = script.Parent.Parent.Parent.Parent.Parent

Why? You should have this in a LocalScript and define the player as game.Players.LocalPlayer instead of doing Parent climbs.

As for your question, you're probably looking to use the math.floor() function which rounds the number down

Example:

local Number = 6.268
local WholeNumber = math.floor(Number)

print(WholeNumber) --6
0
Well when I did the first thing you said which was to put it in a local script and define the Player as game.Players.LocalPlayer it didn't work. Koley_Moley -7 — 3y
0
And would I have to define what number and wholenumber are. And if so how would I define them. I'm bad at this btw. Koley_Moley -7 — 3y
Ad

Answer this question