When you said on line 8:
local Answer = script.Parent.Parent.Answer.Text
You made the variable "Answer" whatever was in that TextLabel/TextBox's text. So if you were to print "Answer" straight after that, you would get whatever was written there at the time.
Therefore when you later on wrote
Answer = <method>
All that did was redefine the variable Answer
to whatever the arithmetic equation came back as, you didn't tell it to change the text.
To fix this, it's very simple.
Simply tell it to actually change the text, rather than store it in the variable Answer
, which is what you were doing.
Furthermore, since you're changing a text to a number, it's a good idea to inform the script. Use the method tostring()
to do this, as seen below.
01 | script.Parent.MouseButton 1 Down:connect( function () |
02 | local Method = script.Parent.Parent.Method.Text |
03 | local Num 1 = script.Parent.Parent.Num 1. Text |
04 | local Num 2 = script.Parent.Parent.Num 2. Text |
05 | local Answer = script.Parent.Parent.Answer |
07 | Answer.Text = tostring (Num 1 +Num 2 ) |
08 | elseif Method = = "-" then |
09 | Answer.Text = tostring (Num 1 -Num 2 ) |
10 | elseif Method = = "*" then |
11 | Answer.Text = tostring (Num 1 *Num 2 ) |
12 | elseif Method = = "/" then |
13 | Answer.Text = tostring (Num 1 /Num 2 ) |
14 | elseif Method = = "%" then |
15 | local Percentage = ( 10 ^- 2 ) * Num 1 |
16 | Answer.Text = tostring (Percentage * Num 2 ) |
17 | elseif Method = = "<" then |
18 | Answer.Text = tostring (Num 1 <Num 2 ) |
19 | elseif Method = = ">" then |
20 | Answer.Text = tostring (Num 1 >Num 2 ) |
21 | elseif Method = = "=" then |
22 | Answer.Text = tostring (Num 1 = = Num 2 ) |
23 | elseif Method = = "^" then |
24 | Answer.Text = tostring (Num 1 ^Num 2 ) |
26 | print ( "The input method is unsupported" ) |