For instance, If I have a gui input or text-box where you can enter information in, I only want to take in numbers so how would I do that? What's the method? Can you point me in the right direction?
Try this.
text = "abcd1234abcd" t = {} --Let's store the numbers in that string. for i = 0, string.len(text) do --Numeric for, counting from 0 to the length of the string. local char = string.sub(text, i, i) --Get the current character you're looking at in the string. if tonumber(char) then --If the character can be a number value table.insert(t, tonumber(char)) --Put the character in the table as a number value end end print(table.concat(t, ", ")) --Just to try it out.
The easiest method to use for what you want to do is string.gsub.
String.gsub basically scans the string for anything that matches the string pattern given and replaces it with a string specified as an argument. You can find the full list of arguments for string.gsub here.
So, how do I use it?
To use it, you need to know a little bit about string patterns. You can find a list of the common string patterns here. The one you're going to be using is %d, which is the string pattern for a number.
So, let's say you had a script in the textbox and you wanted to check for numbers, you could use the Changed event to fire the function each time the box is typed in and a combination of string.gsub and the %d
string pattern which is used for any numerical number.
For example:
local textbox = script.Parent textbox.Changed:connect(function() textbox.Text = textbox.Text:gsub("%d","") --Checks the string for any numbers and replaces it with nothing, essentially removing it. end)
This is not a request site. you would have to show us what you've tried. but if you really need help, i recommend the ROBLOX forums.