Basically, what I want to do is have the player able to put a amount of cash into a textbox and if the input isn't valid, the placeholder text will switch to "Not valid amount of cash!". If you know the solution to my problem please post below. Thanks
✓ ANSWER ACCEPTED
How do you check if text is a number?
1 answer
✓ Accepted answer
You can use the tonumber() function to convert a string to a number. If the string has no number representation then the function returns nil. This function will also return nil if the string has something other than a number; for example, tonumber("1234f") will return nil because it has a letter in it.
local TextBox = script.Parent
TextBox.FocusLost:Connect(function()
local Amount = TextBox.Text
if tonumber(Amount) then
-- Code
else
TextBox.Text = ""
TextBox.PlaceholderText = "Not a valid amount of cash!"
end
end)
Documentation for Converting Strings
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you so much!