How to use less if statements

I heard that a lot of if statements can be inefficient, so i’m just trying to look for a way to use less of them. I’m pretty sure you can use Tables, but i don’t exactly understand how that works yet.

local bet1 = math.random(100,200)
	local bet2 = math.random(200,300)
	local bet3 = math.random(300,400)
	local bet4 = math.random(400,500)
	local bet5 = math.random(100,1000)
	
	if betDPoints > 100 then 
		local Event
		Event = clickBet.MouseClick:Connect(function(playerthatBet)
			Event:Disconnect()
			
			print(betDevice.Name.."has got Stocks")
			local randomChoice = math.random(1, 5)
			print(randomChoice)
			
			--- very if
			if randomChoice == 1 then
				playerPoints.Value = bet1
			elseif randomChoice == 2 then
				playerPoints.Value = bet2
			elseif randomChoice == 3 then
				playerPoints.Value = bet3
			elseif randomChoice == 4 then
				playerPoints.Value = bet4
			elseif randomChoice == 5 then
				playerPoints.Value = bet5

Use a table, and index it.

You can just do.

local bets = {
  math.random(100,200),
  math.random(200,300),
  math.random(300,400)
}

bets[randomChoice]
1 Like

Wow that is what I was gonna post lol

Another, very easy method is to use is

math.randomseed()

As it changes the probability of a random number to be picked. What I said is a very very brief description, you can read more here.

math.randomseed(randomChoice)
local Random = math.random(x,y)

I’m not sure whether you misunderstand OP, or randomseed. Randomseed can’t be used to set the range of numbers used with random.

I said the probability of a random number being picked will be changed. Not range.