Issues with part Positions

Hi! I am getting a weird bug where the positions of my block are weird.

So I have this script:

repeat wait() until workspace.Map

for index, block in ipairs(workspace.Map:GetChildren()) do
	local blockPos = block.Position
	block.Name = blockPos.X .. " " .. blockPos.Y .. " " .. blockPos.Z
end

When I run it I get weird names for the block even though the position is a whole number.

EX:

Can someone help me with this?

It seems like it’s the floating point percision error, this is normal for float data types.

If you print the position of a part you will get a long number with like 10 digits. I would turn that number in to a string than compress it to the first 3-4 digits than make it the parts name.

Most information is contained here:


Previously found in:


Additionally, the numbers used are scientific, using the N * 10^exponent.

You could round up the numbers to avoid the weird decimals.

Hope this helped!

Have a look at string.sub you can call this directly on each X Y and Z using

local x = string.sub(blockPos.Y, 1,3)

I don’t think you can do string manipulation on numbers, correct me if I’m wrong. Also, what if the X is 1000?

one of the solutions on that page is saying work with integers. All of my positions are integers but I still get this bug. What can I do to fix it?

String.Sub should work with numbers as well.

You can always split based off of the length or splitting the string by the “.”

Example: 1000.599e9

Split the string at the “.”, you’ll be left with 1000 and the rest of the digit, perform your string.sub on the second tidbit (if necessary) and then concatenate it back. You can get the length of the string (ex if less than 5 in string length then don’t do anything on the particular X Y or Z value). This is a little bit of a lengthier process and I had not initially thought of it but the above should work if no other better scenario is given.

Alternatively, couldn’t you just use math.floor()? To me it seems more efficient than doing string manipulation on numbers.

Math.Floor() is fine if he is not interested in keeping precision

I need it to be an integer and if I use string.sub on 10s or 1s then it makes it a float still.

Split the string at the “.”

x =15.55
print(string.split(x,“.”)[1])

prints:
15

1 Like