Problem with adding numbers

Hello devs!

I’m making Rebirth system and when the numbers is adding in GUI the text is: x1.100000000001

but I want to add 0.1 to energy and 0.05 to speed

Here is local script:

local RebirthFrame = script.Parent.Rebirth
local EnergyValue = RebirthFrame.Value1
local SpeedValue = RebirthFrame.Value2
local RebirthButton = RebirthFrame.Rebirth
local Require = 10
local EnergyGive = .1
local TrainingGive = .05

	while wait() do
		EnergyValue.Text = "x⚡"..plr.Rebirth.EnergyR.Value + EnergyGive.." Energy"
		SpeedValue.Text = "x👟"..plr.Rebirth.SpeedR.Value + TrainingGive.." Training"

	if plr.leaderstats.Energy.Value >= Require then
		GUIRemotes.Rebirth:FireServer(Require, TrainingGive, EnergyGive)

Here is Script:

local RebirthRemote = GUIRemotes.Rebirth

RebirthRemote.OnServerEvent:Connect(function(plr, Require, SpeedR, EnergyR)
	if plr.leaderstats.Energy.Value >= Require then
		plr.leaderstats.Energy.Value = 0
		plr.leaderstats.Speed.Value = 10
		plr.Rebirth.SpeedR.Value += SpeedR
		plr.Rebirth.EnergyR.Value += EnergyR

You could use math.floor();

print(math.floor(2.32583847473 * 10) / 10)

The script above would print “2.3”

I do recommend looking into remote security right now anyone can change their rebirth speed and energy to whatever they want.


Roblox made a change to tostring recently, which is also called when you use the concatenation operator.

I’m not 100% sure but It could be this.


This is called a floating-point number, which is caused by how computers do math. Using math.floor like @UhTrue said might work in this case, but it is also important to remember that math.floor will always round down. So if it were to ever go the other way, for example “1.29999999999999”, you would want to round to the nearest whole number, not always to the nearest integer that is smaller than that number. Since you’re using 2 decimal place as well, you need to multiply the number first by 100, so you are working with whole numbers, since rounding will not account for decimals.

local energyValue = plr.Rebirth.EnergyR.Value + EnergyGive
energyValue = math.round(energyValue * 100)/100

Alternatively, you could also just limit the number of characters that the text label shows using string.sub(). However, it may still count some 0’s behind the decimal, and if that is the case you can turn it back into a number, so it will ignore that.

local energyValue = tostring(plr.Rebirth.EnergyR.Value + EnergyGive)
string.sub(energyValue, 1, 4) 

Forgot ab that, thanks for helping the op

1 Like