This is a script i have :
local Number1 = workspace.Number1 local Number2 = workspace.Number2 local Number3 = workspace.Number3 local Result = workspace.Result local Operator = workspace.Operator local TextNumber1 = Number1.SurfaceGui.TextLabel local TextNumber2 = Number2.SurfaceGui.TextLabel local TextNumber3 = Number3.SurfaceGui.TextLabel local TextResult = Result.SurfaceGui.TextLabel local TextOperator = Operator.SurfaceGui.TextLabel local Debounce = false local Reset = true local function clicked (player) if Reset == true then local random1 = math.random(1,10) local random2 = math.random(1,10) TextNumber1.Text = random1 TextNumber2.Text = random2 local operations = {"+","-","*","/"} local operator = operations[math.random(1, #operations)] TextOperator.Text = operator Reset = false end if Debounce == false then Debounce = true TextResult.Text = "Waiting" print(""..TextNumber1.Text.. TextOperator.Text ..TextNumber2.Text.."") else if TextNumber3.Text == (""..TextNumber1.Text ..TextOperator.Text.. TextNumber2.Text.."") then local points = player.leaderstats.Points points.Value = points.Value + 1 TextResult.Text = "Correct" Debounce = false Reset = true else Debounce = false Reset = true TextResult.Text = "Wrong" end end end script.Parent.ClickDetector.MouseClick:Connect(clicked)
But, we are only gonna talk about this part of the code :
if TextNumber3.Text == (""..TextNumber1.Text ..TextOperator.Text.. TextNumber2.Text.."") then
Also if needed here :
if Reset == true then local random1 = math.random(1,10) local random2 = math.random(1,10) TextNumber1.Text = random1 TextNumber2.Text = random2 local operations = {"+","-","*","/"} local operator = operations[math.random(1, #operations)] TextOperator.Text = operator Reset = false end
So my problem was how do i make an equation using 3 variable and one of it is the operator? Also if there is a better way to do it please tell, and anyone knows if there is a way to optimize this script please tell too :D
If its not possible please answer an alternative answer (if there is). Thanks :)