I'm trying to do a sort of calculator thing, where it multiplies whatever numbers you put into two Text Boxes when you press a Textbutton. Everytime I press the button, this error shows on the output:
Players.ax_447.PlayerGui.ScreenGui.Script:6: attempt to perform arithmetic on global 'firstvariable' (a string value)
I know I can make it work by making a variable that changes when the string value changes, but for that I have to type in every number individually. Is there any way to do this? If not, is there another way to make the type of thing I'm trying to make?
Hello,
This is the current order of my Gui.
local textbox = script.Parent.Parent.TextBox local pattern = '%d+' function apply(a) textbox.Text = tostring(a) end script.Parent.MouseButton1Click:Connect(function() local tex = (textbox.Text:match(pattern)) if tex == nil then return end print(tex) local fv = tonumber(tex) local sum = fv + 999 local mul = fv * 99 apply(sum * mul) end)
As you can see you can convert a string into a number by simply doing tonumber(String) or the other way tostring(number).
But you will notice that if you type letters together with number you will get an error, I will be using string patterns to bypass those.
Thank you for reading! Goodluck!