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

Equation generator making multiple of same answer every time?

Asked by
ItsMeKlc 235 Moderation Voter
7 years ago
Edited 7 years ago

I'm trying to make a simple equation generator for my game. For the most part it works, but, EVERY time it makes one of the incorrect answers twice. I'm assuming this has something to do with math.random.() I'm trying to use math.random(tick()) but it still isn't fixing it.

(This isn't the entire script)

Have a look at line 45

local pos = 1
local level = script.Parent.Parent.Parent:WaitForChild("correct").Value 
local number1=math.random((level*5)*-1,level*5)
local number2=math.random((level*5)*-1,level*5)
local EquationType = math.random(1,10)
math.randomseed(tick())
if EquationType == 1 or EquationType == 2 or EquationType == 3 then
    script.Parent.question.Text = number1.." + "..number2.." ="
    if number2 < 0 then
        script.Parent.question.Text = number1.." + ("..number2..") ="
    else
        script.Parent.question.Text = number1.." + "..number2.." ="
    end
    answer = ((number1+number2))
elseif EquationType == 4 or EquationType == 5 or EquationType == 6 then
    if number2 < 0 then
        script.Parent.question.Text = number1.." - ("..number2..") ="
    else
        script.Parent.question.Text = number1.." - "..number2.." ="
    end
    answer = ((number1-number2))
elseif EquationType == 7 or EquationType == 8 or EquationType == 9 then
    if number2 < 0 then
        script.Parent.question.Text = number1.." x ("..number2..") ="
    else
        script.Parent.question.Text = number1.." x "..number2.." ="
    end
    answer = ((number1*number2))
elseif EquationType == 10 then
    if number2 < 0 then
        script.Parent.question.Text = number1.." / ("..number2..") ="
    else
        script.Parent.question.Text = number1.." / "..number2.." ="
    end
    answer = math.floor((number1)/(number2)*10)/10
end
for i,v in pairs(script.Parent:GetChildren()) do
    if v.ClassName == "TextButton" then
        v.Position = positions[pos]
        pos = pos + 1
        if v.Name == "correct" then                 
            v.Text = (answer)           
        elseif v.Name == "incorrect" then
            repeat
                print("trying to select wrong number")
                wait()
                local EquationType = math.random(1,10)
                if EquationType == 1 or EquationType == 2 or EquationType == 3 then
                    wanswer = ((number1+number2))
                elseif EquationType == 4 or EquationType == 5 or EquationType == 6 then
                    wanswer = ((number1-number2))
                elseif EquationType == 7 or EquationType == 8 or EquationType == 9 then
                    wanswer = ((number1*number2))
                elseif EquationType == 10 then
                    wanswer = math.floor((number1)/(number2)*10)/10
                end
            until wanswer ~= answer 
            v.Text = (wanswer)
        end 
    end
end

1 answer

Log in to vote
0
Answered by
ItsMeKlc 235 Moderation Voter
7 years ago

I feel so dumb right now but I've fixed it... I needed to restate number1 and number2

Ad

Answer this question