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
spawn(function()
while wait() do
EnergyValue.Text = "x⚡"..plr.Rebirth.EnergyR.Value + EnergyGive.." Energy"
SpeedValue.Text = "x👟"..plr.Rebirth.SpeedR.Value + TrainingGive.." Training"
end
end)
RebirthButton.MouseButton1Click:Connect(function()
if plr.leaderstats.Energy.Value >= Require then
GUIRemotes.Rebirth:FireServer(Require, TrainingGive, EnergyGive)
end
end)
Here is Script:
--[[Rebirth]]--
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
end
end)
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.
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)