Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago

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

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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
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 aileron_roll 5 — 6y
0
@aileron_roll accept answer? DanzLua 2879 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

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

Answer this question