Need Help With Fixing Script

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix the problem.

  2. What is the issue? Include screenshots / videos if possible!
    When I check if the question is a or b the code doesn’t go through.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t tried any solutions, and I haven’t gone to look for solutions.

local Q = {"What is a square root", "What is a sqaure"}

local N = {1,2}

local RN = N[math.random(1, #N)]

local RQ = Q[math.random(1, #Q)]

local CA
local WA

local B1 = script.Parent.RightButton
local B2 = script.Parent.LeftButton

script.Parent.TextLabel.Text = RQ

function AlG()
	
	if Q == "What is a square root" then 
		CA = "a number which produces a specified quantity when multiplied by itself."
		WA = "I only do right answers"		
	end
	
	if Q  == "What is a square" then
		CA = "multiply (a number) by itself."
		WA = "You know the answer"
	end
	
	if N == 1 then
		B1.Text = WA
		B2.Text = CA
	elseif N == 2 then
		B1.Text = CA
		B2.Text = WA

	end
	

end

AlG()

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

The variables CA and WA are blank does it give you an error message?Also I have noticed that your conditional statements is missing something

This is because you aren’t actually accessing the values in the table in any way. When you are trying to compare Q, you are referencing the table | Roblox Creator Documentation itself, not the actual content inside of it.

If you actually wanted to access a value inside of the array, you could do it using the numerical index of the value in the array. In this case, you have set it up so that there are two (questions?) options to ask. If you wanted to access option 1, "What is a square root", you could do Q[1] because 1 is it’s numerical index in the array. Other languages are zero-index, but you don’t have to worry about that for right now.

Also, you are using variables incorrectly. Particularly the CA and WA variables. With the way you are using them, they are absolutely useless. You don’t need to assign them if you are only going to set something else to that variable.

You can learn more about Tables | Roblox Creator Documentation by clicking on the article links I’ve provided. When iterating through tables, you can use https://education.roblox.com/en-us/resources/pairs-and-ipairs-intro.

You can try this. It may not be what you were hoping, but if you want to have a function perform a specific action or return a specific output, you must have a defining input.

local Q = {"What is a square root", "What is a square"} -- fixed spelling issue with "sqaure"
local N = {1,2}

local RQ = math.random(#Q)
local RN = math.random(#N) -- you can just do the length of the table without adding the "1"; it does the same thing

local B1 = script.Parent.RightButton
local B2 = script.Parent.LeftButton

script.Parent.TextLabel.Text = Q[RQ]

local function setText(text1, text2, order) -- this function exist because of the do not repeat yourself coding principle
	B1.Text = if order == 1 then text1 else text2
	B2.Text = if order == 1 then text2 else text1
end

local function AlG(questionIndex, order)
	if Q[questionIndex] == "What is a square root" then
		setText("I only do right answers", "a number which produces a specified quantity when multiplied by itself.", order)
	elseif Q[questionIndex] == "What is a square" then
		setText("multiply (a number) by itself.", "You know the answer", order)
	end
end

AlG(RQ, RN)
2 Likes

It’s hard to tell what you’re trying to do here. “What do you want to achieve?” followed by “I want to fix the problem” gives almost no insight.

Also, your variable naming doesn’t help.

4 Likes

Like what NoParameters said, we have literally no idea what you want to achieve. Please elaborate on your code and, well, what you’d like to achieve.

2 Likes