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 10 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.

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

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
10 years ago
math.random(143, 113)

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

math.random(113, 143)

Other than that, it looks fine :)

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

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

Ball.Position = Vector3.new(math.random(-19,82),55,math.random(143,113))

--i switched the last numbers around to this
math.random(143,200))
--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

function partyball()
    for i = 1,100 do -- switch to a while loop if you want
    Ball = game.ServerStorage.PartyBall:Clone()
    Ball.Position = Vector3.new(math.random(-19,82),55,math.random(143,200))
    Ball.Parent = Workspace 
wait()
end
end
partyball()

1
Thank you as well! By the way, I had a loop running this function :) User#348 0 — 10y
0
No problem and oh i didn't know lol. Damo999 182 — 10y