How do i fix those weird numbers?

Hello guys, i’m a beginner scripter and i was making a time trial game,

I don’t know why i keep getting these weird numbers:
image

I have no idea how to fix it, i dont know many things about scripting, so any of you can help me to fix it.
I tried many things, and it still didnt work.

1 Like

show me your text time script

i can help you

ok wait i will send it rlly soon

local timer = script.Parent.Timer

local startPart = workspace.start
local endPart = workspace.endPart

startPart.Touched:Connect(function()
	timer.TextColor3 = Color3.fromRGB(133, 255, 112)
	
	for i = 0, (1/0), 0.01 do
		repeat
			timer.Text = i
			
			task.wait()
			
		until endPart.Touched
	end
end)

endPart.Touched:Connect(function()
	if tonumber(timer.Text) > 0 then
		timer.TextColor3 = Color3.fromRGB(255, 255, 255)
	end
end)

im also having that bug that the timer doesnt stop when i touch the endPart lol

ok i will try to fix the issue!
give me a moment

ok sorry i will have to do something important i will be offline maybe for an hour, i will still help you if i finished my things

1 Like

use math.round(urnumberhere), it’ll be rounded to the closest integer

Use math.round(variable here) to round to the nearest number, math.floor(variable here) to round down

2 Likes

Thank you! You learned me something new today! :smiley:

1 Like

What you’re experiencing is know as a ‘floating point error’ and it’s caused by how decimal numbers are represented by computers. I won’t go into the specifics of why this happens because it’s beyond the scope of what you need to know at the moment but if you study computer science at school, you will likely cover it at some point.

The easiest and most common way to deal with this issue is simply to round or truncate the result.
I’m guessing you want to retain two decimal places of accuracy and so the correct method for rounding would be.

function roundToHundredths(numberToRound)
  
  numberToRound *= 100
  local result = math.round(numberToRound)
  result /= 100
  return result
  
end

If you want a more versatile version of this function, you can check out this on the lua-users wiki.

If you want a more indepth explanation regarding why this issue occurs, then you can take a look at this webpage.

Note that neither of these webpages are Roblox sanctioned sites, so proceed with caution.

i was going to do that solution and actually fix all the problem he is getting but i decided to do something else and i didn’t solve the topic.

and when i was going to send the solution my roblox studio crashed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.