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

Problems with math.random [closed]

Asked by 11 years ago

Hello! I am attempting to make a script that makes balls fall from the sky into random places, but I am getting an error. This is the function I am using.

1function partyball()
2    Ball = game.ServerStorage.PartyBall:Clone()
3    Ball.Position = Vector3.new(math.random(-19, 82), 55, math.random(143, 113))
4    Ball.Parent = Workspace
5end

When this function runs, I get the following error in the output. Workspace.Party.Core Script:52: bad argument #2 to 'random' (interval is empty) I am not sure what is causing the problem, hopefully you can help. Thank you for taking your time to read this.

Locked by TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
5
Answered by
TheMyrco 375 Moderation Voter
11 years ago
1math.random(143, 113)

The lowest value should be given first, then follows the highest value

1math.random(113, 143)

Other than that, it looks fine :)

Ad
Log in to vote
3
Answered by
Damo999 182
11 years ago

Well i fixed it the only thing that was stopping the script from running for me was this ling here

01Ball.Position = Vector3.new(math.random(-19,82),55,math.random(143,113))
02 
03--i switched the last numbers around to this
04math.random(143,200))
05--i suspect that the first parameter has to be higher than the second one or it will not run also if you want multiple balls to fall from the sky you need to add either a while loop or a for loop
06 
07function partyball()
08    for i = 1,100 do -- switch to a while loop if you want
09    Ball = game.ServerStorage.PartyBall:Clone()
10    Ball.Position = Vector3.new(math.random(-19,82),55,math.random(143,200))
11    Ball.Parent = Workspace
12wait()
13end
14end
15partyball()
1
Thank you as well! By the way, I had a loop running this function :) User#348 0 — 11y
0
No problem and oh i didn't know lol. Damo999 182 — 11y