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

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

Asked by 5 years ago

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!!

1
Can you try to switch the numbers? math.random( -595, -565) User#20388 0 — 5y
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! :( BabyDevil285 9 — 5y
0
Not sure, let me try BabyDevil285 9 — 5y

2 answers

Log in to vote
2
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

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)
0
The problem with that is then the SCP will not teleport inside the specified grid :( BabyDevil285 9 — 5y
1
Then you're doing it wrong Rare_tendo 3000 — 5y
0
No I already have the answer :DDD BabyDevil285 9 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

0
No problem xD User#20388 0 — 5y
0
this should be a comment just for you to know :| fanofpixels 718 — 5y
0
But Do I care? No. BabyDevil285 9 — 5y

Answer this question