Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I got a bad argument (interval is empty) error with this script, what does this mean?

So I'm trying to make a script that moves a part 10 times in a randomly selected x and z position.

part = script.Parent
local x = math.random(100, -100)
local z = math.random(100, -100)

for i = 1, 10 do
	wait(1)
	part.Position = Vector3.new(x, 15, z)
end

However when I run it it gives me this error:

Workspace.Part.Script:2: bad argument #2 to 'random' (interval is empty)

I don't know what this means.

2 answers

The reason this is happening is because you gave the arguments for the math.random incorrectly. math.random() gives us a random number between blah and blah, less to more. What you did was give it more to less which doesn't really work, instead of

math.random(100,-100)

do

math.random(-100,100)

Here is your script fixed

part = script.Parent
local x = math.random(-100, 100)
local z = math.random(-100, 100)

for i = 1, 10 do
    wait(1)
    part.Position = Vector3.new(x, 15, z)
end

2 comments

0

oh ok thanks, I know there are some other bugs in the code but I'll figure them out by myself, right now all I really needed was the answer to my question

0

@aileron_roll accept answer?

looks like your math.randoms aren't quite right! when using math.random(), the minimum value must be provided first, followed by the maximum value. simply switching the numbers on your snippet should solve the problem.

part = script.Parent
local x = math.random(-100,100)
local z = math.random(-100,100)

for i = 1, 10 do
    wait(1)
    part.Position = Vector3.new(x, 15, z)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.