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

Can someone help me with this random.math script because its only working for one of the valiues?

Asked by 5 years ago

Hello,

I am trying to make a math.random() values but its only taking 1 and not 2 why?

script.Parent.Bet.Conrim.MouseButton1Click:Connect(function()
    script.Parent.mainFrame.Reward.MoneyToGet.Value = script.Parent.Bet.Bet.Text
    script.Parent.Bet.Visible = true
    local WinningColor = math.random(1,3)
    if WinningColor == 1 then
        for i = 1,3 do
            script.Parent.mainFrame.Green.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0.6
            wait(.3)
            script.Parent.mainFrame.Red.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Green.BackgroundTransparency = 0
            wait(.3)
            script.Parent.mainFrame.Green.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Red.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0
            wait(.3)
            script.Parent.mainFrame.Green.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Red.BackgroundTransparency = 0
            wait(.3)
        end
        if WinningColor == 2 then
            for i = 1,3 do
            script.Parent.mainFrame.Green.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0.6
            wait(.3)
            script.Parent.mainFrame.Red.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Green.BackgroundTransparency = 0
            wait(.3)
            script.Parent.mainFrame.Green.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Red.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0
            wait(.3)
            script.Parent.mainFrame.Green.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Black.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Red.BackgroundTransparency = 0
            wait(.3)
            script.Parent.mainFrame.Black.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Red.BackgroundTransparency = 0.6
            script.Parent.mainFrame.Green.BackgroundTransparency = 0
            wait(.3)
            end
        end
    end
end)
0
It's random, test it like 50 times, we'll talk again if 3 doesn't appear User#17685 0 — 5y
0
And your script only had 'if's condition for 1 and 2, 3 will be useless. User#17685 0 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

The if statement for 2 will never run because it's inside of if WinningColor == 1 statement.

Put your second if statement outside of the first one and you're good

Ad

Answer this question