Way to set a string value to a number value?
Asked by
4 years ago Edited 4 years ago
I making code that will add two numbers that are put into a TextBox's Text property and return an answer into another TextBox. The code works perfectly, but if I type in a string and click the CalculateButton, it will give this error in the output: Players.Green_Lime2.PlayerGui.ScreenGui.CalculateButton.LocalScript:15: attempt to perform arithmetic (add) on string
Is there any way to block the strings and only accept numbers?
The LocalScript is inside the CalculateButton.
Here's the code:
01 | print ( "Ready for calculating" ) |
05 | local player = game.Players.LocalPlayer |
06 | local character = player.Character |
07 | local playergui = game.Players.LocalPlayer.PlayerGui |
08 | local calculatebutton = playergui.ScreenGui.CalculateButton |
09 | local textbox 1 = playergui.ScreenGui.TextBox 1 |
10 | local textbox 2 = playergui.ScreenGui.TextBox 2 |
11 | local answerbox = playergui.ScreenGui.AnswerBox |
13 | calculatebutton.Activated:Connect( function (activated) |
15 | answerbox.Text = textbox 1. Text + textbox 2. Text |