Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to remove all the alphabets from a textbox but only works for letter a?

Asked by 5 years ago

Hi. So I wanted to make like a number only textbox. So I am trying to remove all the alphabets written on the textbox. However, the solution I have come up with only works for letter a which is the first letter in the module script I wrote. Is there a reason why this is happening? There are no errors btw.

Your help would be kindly appreciated.

local Player = game:GetService("Players").LocalPlayer 
local PlayerGui = Player:WaitForChild("PlayerGui") 

local Screen = PlayerGui:WaitForChild("Screen") 
local Box = Screen:WaitForChild("Box") 

local Get_Text = Box.Text 
local Debounce = false 
local text = "" 

local Alphabets = require(script:FindFirstChild("Alphabets")) 

local function RemoveString (Character, String)
    local StringTab = {} 

    for a = 1, string.len(String) do
        local CurrentString = string.sub(String, a, a) 
        table.insert(StringTab, a, CurrentString) 
    end 

    for __, value in pairs (StringTab) do
        if value == Character then
            table.remove(StringTab, __) 
        end 
    end 

    local FinalString = table.concat(StringTab)
    return FinalString 
end 


local function CheckStuff ()
    if Debounce then return end 
    Debounce = true     

    if Get_Text ~= Box.Text then 
        Get_Text = Box.Text 
    end 

    local Main_Text = Get_Text:gsub("[%s]", "") 

    if Main_Text == "" then
        print("NO CURRENT TEXT!") 
    end 

    local FinalString = RemoveString(unpack(Alphabets), Main_Text) 
    print(FinalString)
    Box.Text = FinalString 
    Debounce = false 
end 

Box.Changed:Connect(CheckStuff) 

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Couldn't you just use :match(pattern)?

local onlyNumbers = (Box.Text):match("%d+")

Take a look on patterns

But, trying to solve your problem, unpack returns the elements of a table, so it will set Character as the first character of the list. You probably will need to do some very complicated stuff to fix this, so I recommend using patterns, which will save you a lot of time.

0
Thanks but I already had solved it with another way. Still gonna accept ur ans lol LightYagamiTheKira 116 — 5y
Ad

Answer this question