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

Keep running in to this error: Bad argument #2 to 'random' (interval is empty). How can I fix this?

So, I know that this type of question has been answered but none of that helped me!! :(

Here is the error: bad argument #2 to 'random' (interval is empty)

The reason is that I am making an SCP game with my friend, and for SCP-173, I need a random tp script. What I have so far is a specified grid on where it can move.

Here is the script:

-- // Developed By BabyDevil285 \\ --

-- // Variables

local scp = script.Parent
local torso = scp.Torso
local hum = scp.Humanoid
local movementgrid = workspace.SCP_173_MovementGrid
local scpXmovement = math.random(-565, -595)
local scpZmovement = math.random(148, 188)

-- // Functions

local function Slide()
	torso.Position = Vector3.new(scpXmovement, 0, scpZmovement)
end

-- // Slide Event

while true do
	wait(math.random(4, 17))
	Slide()
end

-- // Kill Event

-- Soon.

The line of error: 9

Please help!!

3 comments

1

Can you try to switch the numbers? math.random( -595, -565)

0

Just saying, I believe the error appears because I'm using negative numbers! However I need those negative numbers so that the SCP stays inside the specified grid! :(

0

Not sure, let me try

2 answers

bad argument #2 to 'random' (interval is empty) usually occurs when the first argument is larger than the second. -595 is less than -565.

Instead at line 9, do:

local scpXmovement = -math.random(565, 595)

3 comments

0

The problem with that is then the SCP will not teleport inside the specified grid :(

1

Then you're doing it wrong

0

No I already have the answer :DDD

OMG!! CREDIT GOES TO RedcommanderV2 FOR ANSWERING MY QUESTION!! I'VE BEEN TRYING TO FIXURE THIS OUT THE WHOLE NIGHT YESTERDAY. THIS MEANS A LOT TO ME :DDDDDD

3 comments

0

No problem xD

0

this should be a comment just for you to know :|

0

But Do I care? No.

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