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

Why wont this wait?

Asked by 9 years ago

I don't know how to make the time wait like 25-500.I also tried wait(25-30) i dont know how it works im still learning... :/

local TimeLimit = {
170,
120,
180,
240,
300,
360,
630,

}

wait(math.random(1, #TimeLimit))

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

math.random(low, high) returns a random number between low and high (inclusive).

For this, low is 1 and high is #TimeLimit, or 7. That means math.random(1, #TimeLimit) is one of 1, 2, 3, 4, 5, 6, or 7 -- not one of the things in the TimeLimit list.

You probably wanted to get a random thing from the list TimeLimit. Since the things inside TimeLimit are TimeLimit[1], TimeLimit[2], ..., TimeLimit[7], you just have to use

wait( TimeLimit[ math.random(1, #TimeLimit) ] )

Also note that the 1 is optional:

wiat( TimeLimit[ math.random(#TimeLimit) ] )
Ad

Answer this question