Hello. I tried to make the round number on my coin gui, but from 578915 i got 5,78915. How to remove all after 5,7?
Code:
local Value = game.Players.LocalPlayer.leaderstats.Coins.Value
function renew()
if Value >= 10000 and Value < 100000 then
parent.Text = Value /10000
end
end
while wait(.1) do
renew()
end```
I believe to round to the nearest 10, you can multiply the current number by 10, round it, then divide it by 10.
Quick implementation
function RoundNumToNearestTenth(num)
local NearestTenth = (math.round(num * 10))/10
end
Also, rather than running a loop every 0.1 seconds, you should use events, like so:
local Coins = game.Players.LocalPlayer.leaderstats.Coins
function renew()
if Coins.Value >= 10000 and Coins.Value < 100000 then
parent.Text = Coins.Value / 10000
end
end
Coins.Changed:Connect(renew)
renew()
--define the services you use
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
--store the reference to the object not the value!(else it will remain constant)
local Coins = Player.leaderstats.Coins
function floor(num, decimalDigits)
local x = 10^decimalDigits
return math.floor(num*x)/x
end
function renew()
--flooring the value to 1 decimal digit
if Coins.Value >= 10000 and Coins.Value < 100000 then
parent.Text = floor(Coins.Value/10000, 1)
end
end
--instead of looping, run the function every time the coins update
renew() --and also once at the start
Coins.Changed:Connect(renew)