Picking out only numbers from a string

Hey, I was trying to make a system that picks out numbers from a string that contains both letters and numbers. But I have no idea how to do that.

local String = "Stat: 20" --A function is supposed to only pick the number 20 while ignoring everything else.

I have tried looking in developer.roblox.com website as well as in the devforum.roblox.com for info or reference, but I couldn’t find what I was looking for.
Any help is appreciated, thanks!

function ToNumber(String)
    local Finished, _ = string.gsub(String,"%a+", "")  
    return Finished
end

print(ToNumber("Hello 2852 aaa")) -->>  2852 
1 Like