What does this error mean?

Hello there, ladies and gentlemen!

I am recently having this error pop up and I dont know what to do, because this is my first time seeing this error:

This is the faulty line:

	local posX = (math.random((game.Workspace["DAF XF"].Body.XYGlass.Position.X-game.Workspace["DAF XF"].Body.XGlass.Position.X)*100)/100)+game.Workspace["DAF XF"].Body.XGlass.Position.X

It means that the first argument of math.random() exceeds the 32-bit integer limit (2,147,483,647). From what I could scavenge from the mess, that would be:
(game.Workspace["DAF XF"].Body.XYGlass.Position.X-game.Workspace["DAF XF"].Body.XGlass.Position.X)*100)
I believe you can just follow the post that I found here (with a quick google search):

1 Like

Wait I’m actually confused what your line of code was trying to achive…What sort of random number? One between 0 and a bigger number? Because you need two numbers for a math.random function, a minimum, and a maximum. The latter must of course be bigger than the former. For example:

local posX = (math.random(0, (game.Workspace["DAF XF"].Body.XYGlass.Position.X-game.Workspace["DAF XF"].Body.XGlass.Position.X)*100)/100)+game.Workspace["DAF XF"].Body.XGlass.Position.X

Make the zero any number as long as you know its less than the number after the comma.

I would suggest formatting it like this

local max = (((game.Workspace["DAF XF"].Body.XYGlass.Position.X-game.Workspace["DAF XF"].Body.XGlass.Position.X)*100)/100)
local addtional = game.Workspace["DAF XF"].Body.XGlass.Position.X
print("max: "..max)
print("additional: "..addtional)
local posX = math.random(0, max + addtional)

One between 0 and the length of a front glass of a truck.

Well this is erroneous, sorry:

It must be greater than or equal to the former. So you could have math.random(1, 1)

Alright! Tell me if my code works then.

1 Like

Sadly, it made it worse. Instead of moving your truck somewhere, it does it at the beginning:

Try this

local posX
local interval = game.Workspace["DAF XF"].Body.XYGlass.Position.X - game.Workspace["DAF XF"].Body.XGlass.Position.X
if interval ~= 0 then
    posX = (math.random(interval * 100) / 100) + game.Workspace["DAF XF"].Body.XGlass.Position.X
else
    -- Handle the case when interval is 0
end

This ensures that the math.random function is only called when the interval is non zero.

local max = (((game.Workspace["DAF XF"].Body.XYGlass.Position.X-game.Workspace["DAF XF"].Body.XGlass.Position.X)*100)/100)
local addtional = game.Workspace["DAF XF"].Body.XGlass.Position.X
print("max: "..max)
print("additional: "..addtional)
if max + additional == 0 then additional += 1 end
local posX = math.random(0, math.floor(max + addtional))
1 Like

Anyways I somehow fixed it, when I fixed an other bug where the raindroplets fell randomly to their death. The problem occured whenever the rainvalue has changed it will fire the second copy of the same script and the first copy will stop.


Hope it will be not temporary

Good news! Mark your post as the solution then and if a problem occurs in the future, be sure to open a new topic.

1 Like

Edit: The fix I mentioned was luck, because it seems that I forgot to insert the second argument and still, somehow, made it work.

Here are possible causes:

  • Rotation - Rotation can cause the first part’s position to be higher than the second’s.

Edit 2:
My theory of Rotation is proven wrong:

image

Note: Numbers marked yellow are X positions of those two parts, in the same order as the problematic line…

Have you tried my solution of math.flooring the numbers before math.randomizing them?

No, but I might edit it to match my needs.