[solved]Studs calculation is not accurate

Hello all.
I was making a studs/movement project and I ran into an issue regarding the calculation. I’ve been trying different methods but none of them is what I’m looking for. One using math.round() didn’t work because I am using a task.wait() while loop. Using math.ceil() it would also been inaccurate. Without using a math library function its fine but gives me a big decimal point. I don’t want the big decimal so I would round that and it would loose the progress from the decimal so it wouldn’t work. My final way to fix was using math.modf()'s integer but it was inaccurate during testing. So I basically want it to be a whole number but without loosing the progress from the decimal.


script.LocalScript:Clone().Parent = game.StarterPlayer.StarterCharacterScripts --not relevant to issue

local Players = game:GetService("Players")
local Billboard = game:GetService("ServerStorage"):WaitForChild("BillboardPart")


	local character = Player.Character or Player.CharacterAdded:Wait()
	local humanoid = character:FindFirstChild("Humanoid")
	local humanoidrootpart = character:FindFirstChild("HumanoidRootPart")

	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	local StudsValue = Instance.new("NumberValue", leaderstats)
	StudsValue.Name = "Studs"
	StudsValue.Value = math.random(325, 655)
	local start = StudsValue.Value

	local NewBillboard = Billboard:Clone()
	NewBillboard.BillboardGui.PlayerName.Text = Player.Name.." has"
	NewBillboard.Parent = workspace

	NewBillboard.Name = Player.Name .. "'s Billboard"

	while true do
		local LastPosition = humanoidrootpart.Position
		NewBillboard.BillboardGui.studs.Text = StudsValue.Value
		local Delta = ((humanoidrootpart.Position - LastPosition).Magnitude)
		local NewDelta = StudsValue.Value - Delta
		local integer, frsction = math.modf(NewDelta)
		print(integer, frsction)
		StudsValue.Value = integer

The problem is at the while loop.


I found a way to get around it with perfect accuracy.

How’s that if you don’t mind me asking?

Sorry for the inconvenience