Help on rounding up numbers with a lot of decimal points

Im currently working on a game that uses a distance travelled counter, but i ran into a problem where
the counter have a lot of decimal points in it. I’ve tried math.ceil() and math.floor() but it doesnt seem to
work or maybe im doing something wrong.

image

The script:

local TotalStudsWalked = {}
while wait do
	for i,Player in pairs(game.Players:GetPlayers()) do
		if Player.Character then
			local Humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
			if Humanoid.MoveDirection.Magnitude > 0 then
				if OldPosition[Player.UserId] then
					local newDistanceTravelled = (Humanoid.RootPart.Position - OldPosition[Player.UserId]).Magnitude
					TotalStudsWalked[Player.UserId] = TotalStudsWalked[Player.UserId] + newDistanceTravelled
					--math.round(script.Parent.Text)
					script.Parent.Text = script.Parent.Text + (newDistanceTravelled / 5)
					
					OldPosition[Player.UserId] = Humanoid.RootPart.Position
				else
					TotalStudsWalked[Player.UserId] = 0
					OldPosition[Player.UserId] = Humanoid.RootPart.Position
				end
			end
		end
	end
	wait(0.1)
end```

Why not just use math.round()?

1 Like

Are you trying to round your number to a specific number of decimal places? For example:

11.456 → 11.5

Or, are you rounding to the nearest whole number?

11.567 → 12

the nearest whole number. also tried math.round() still cant seem to make it work

Ah, I know why. The Text value is a string, and you cannot run math functions on string values.

Replace this line:

With this:

script.Parent.Text = math.round(tonumber(script.Parent.Text) + (newDistanceTravelled / 5))
1 Like