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:
script.LocalScript:Clone().Parent = game.StarterPlayer.StarterCharacterScripts --not relevant to issue
local Players = game:GetService("Players")
local Billboard = game:GetService("ServerStorage"):WaitForChild("BillboardPart")
Players.PlayerAdded:Connect(function(Player)
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
print(start)
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
task.wait()
local Delta = ((humanoidrootpart.Position - LastPosition).Magnitude)
local NewDelta = StudsValue.Value - Delta
local integer, frsction = math.modf(NewDelta)
print(integer, frsction)
StudsValue.Value = integer
end
end)
The problem is at the while loop.
Thanks!
@Tomroblox54321