I believe the issue comes from the compiler not understanding what line 39 is as currently the compiler thinks it’s as weird syntax as I’m assuming the Values are string values from a text box GUI like so:
TL.Text = "num1 value" "num 2 value" "num 3 value"
Yeah, the machine compiler reading it is thinking of which variable to assign TL.Text with num1 value, num2 value, or num3 value and is yeah confused and will prompt an error.
To solve it we can use a function dictionary to translate a string value into the proper Lua mathematical syntax the compiler will understand what to do with.
local Frame = script.Parent.Parent.Parent.Numbers
local Buttons = Frame:GetChildren()
local Frame = script.Parent.Parent.Parent.Numbers
local Buttons = Frame:GetChildren()
local TL = script.Parent.TextLabel
local num1 = script.Parent.Number1
local num2 = script.Parent.Number2
local PrefixVal = script.Parent.Prefix
local prefixes = {
"/";
"-";
"*";
"+"
}
--Translate string into mathematical expression
local prefixesFunctions = {
["/"] = function (number1,number2)
return number1/number2
end;
["-"] = function (number1,number2)
return number1 - number2
end;
["*"] = function (number1,number2)
return number1*number2
end;
["+"] = function (number1,number2)
return number1+number2
end;
}
local enter = "="
local Numbers = {
"0";
"1";
"2";
"3";
"4";
"5";
"6";
"7";
"8";
"9"
}
while wait(0.1) do
for i, v in pairs(Buttons) do
v.MouseButton1Click:Connect(function()
if prefixes[v.Name] then
local prefix = prefixes[v]
TL.Text = TL.Text .. prefix
PrefixVal.Value = prefix
end
if v.Name == enter and num1.Value ~= 0 and PrefixVal.Value ~= "" and num2.Value ~= 0 then
local number1 = tonumber(num1.Value)
local number2 = tonumber(num2.Value)
--Use the dictionary to find the correct mathematical syntax
local answerNumber = prefixesFunctions[PrefixVal.Value](number1,number2)
TL.Text = tostring(answerNumber) --[[ line 39. U can see why there is a problem... But when a player put in 2 numbers and a prefix why won't line 39 look like this: TL.Text = 10 / 5 ??? ]]--
else
-- Player didn't complete the input.
end
if Numbers[v.Name] then
if num1.Value == 0 then
num1.Value = v.Name
TL.Text = v.Name
else
if num2.Value == 0 then
num2.Value = v.Name
TL.Text = TL.Text .. v.Name
else
print("Max numbers reached")
end
end
end
end)
end
end
This should translate string into lua mathematical expressions. Hopefully, it works haven’t tested it out.