Seemingly simple error with math.random, however can't seem to fix it

Hi all,
Just needed some help with fixing this seemingly innocent error, however, it has been causing me quite a pain in the behind for about half an hour now. If anybody could tell me in which pair(s) of parentheses I might’ve done incorrectly, that would be greatly appreciated.

Exact line of code where error occurs:
blockInstance is a part, caveSizeY is a number

local cavePositionY = math.random(math.round(blockInstance.Position.Y/blockInstance.Size.Y - caveSizeY/2), math.round((blockInstance.Position.Y - 3)/blockInstance.Size.Y - caveSizeY/2)) * blockInstance.Size.Y

Error:
image

Better organized code:

local cavePositionY = math.random(
math.round(blockInstance.Position.Y/blockInstance.Size.Y - caveSizeY/2), 
math.round((blockInstance.Position.Y - 3)/blockInstance.Size.Y - caveSizeY/2)
) * blockInstance.Size.Y

could you print out the values you are trying to get?

1 Like

Did you try math.floor?

local cavePositionY = math.floor(math.round(blockInstance.Position.Y/blockInstance.Size.Y - caveSizeY/2), math.floor((blockInstance.Position.Y - 3)/blockInstance.Size.Y - caveSizeY/2)) * blockInstance.Size.Y

I believe it should print out a number around ~2048,not exactly sure due to the usage of the math.random however

Well did you debug your code at all? Just add a print above the code and see what the math.random values give you. You need to debug your code before asking us for answers we cannot even give you, because you only provided a line of your code.