Why isn't my code calculating accurately?

So, here’s the code I used, but it doesn’t calculate accurately ( Just test it and you’ll see by yourself ):

local number = 0

while true do
	wait(0.1)
	number = number + 0.1
	game.Workspace.Name = number
end

I’m testing it on the Workspace name cuz the output doesn’t work for me for some reason

How can I get it to calculate accurately ?

2 Likes

Quick question, What is the run context?

1 Like

It doesn’t work with IntValues. I tested it, and I even made some edits on your code, but still doesn’t work.

It worked with NumberValue, but still calculates inaccurately.

RunContext is set to Legacy , but does that even matter?

It doesn’t work on IntValues because they can only store whole numbers. Since you are adding 0.1, it wont work until you get a whole number (i.e. 1, 2, 3)

Honestly I’m asking if it is a local or a serverscript, some syntaxes aren’t valid depending on which script type.

Yea I get it. Thanks for the info!

definitely string value then, correct?

It’s a ServerScript.

[lettersss]

Its time to start working on your math | Documentation - Roblox Creator Hub
MATHS!

1 Like

Send me any link except the Documentation because I barely understand a thing from it.

Then you will not get far in programming… sorry… the documentation is the best way to learn, as it is them telling us how they built the engine lol…

1 Like

I know, but I’m trying my best to understand it … My native language isn’t English.

What makes it hard to understand is that there are tens of words that I haven’t read or heard of before. Translation also doesn’t help a lot.

But my English will most likely improve a lot as I grow up, and when it does, I’ll start reading the Documentation and try to understand it.

I’m currently relying on YouTube tutorials, thinking and creativity.

1 Like

I think I understand your problem. You want a way so that numbers are always 0.3 instead of 0.30000000000000004 for example. If so, then the issue you have is because of something called “floating-point errors” which is caused by the way computers calculate float values or fractions (0.3 is a float value) and to solve it you will need to do this:

local workspace = game:GetService"Workspace"

local number = 0
local precision = 10 -- If you want to increase number by 0.01 then this will need to be 100 and so forth

local round = math.round

while true do
	task.wait(0.1)
	number += 0.1
	workspace.Name = round(x * precision) / precision
end
2 Likes

It doesn’t work:(

the word x in line 11 is underlined blue

1 Like

Hello!

That’s because x isn’t defined. It is nil, or nothing. Try changing it to number.

Hope this helps! :slight_smile:

1 Like

Thank you so much!

It works!

Now Imma break every line in this code down and try to understand how it works.

And thanks for your help!

1 Like

You’re welcome! Any time! :smiley:

[char limit]

1 Like

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