generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: A number-only textbox

Previous Thread :: Next Thread 
DragonOfWar900 is not online. DragonOfWar900
Joined: 11 May 2011
Total Posts: 1508
26 Apr 2014 07:29 PM
function CheckForNums(Box)
if Box:IsA("TextBox") then
TT = {}
for i=1, #Box.Text do
TT[#TT] = Box.Text
end
Box.Text = ""
for _,v in pairs(TT) do
if tonumber(v) ~= nil then
Box.Text = Box.Text..v
end
end
end
end

while wait() do CheckForNums(script.Parent) end

Well, this will make that you can only type numbers on the textbox.
The only problem is that when you already typed a number, and then type a letter, the entire number gets deleted.
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 Apr 2014 07:45 PM
Box.FocusLost:connect(function()
Box.Text = string.gsub(Box.Text, "[^%d,]+", "")
end)
Report Abuse
Devoi is not online. Devoi
Joined: 09 Jun 2013
Total Posts: 5387
26 Apr 2014 08:05 PM
Box.Changed:connect(function()
Box.Text = string.gsub(Box.Text, "[^%d,]+", "")
end)

y u do dis echo
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
26 Apr 2014 08:19 PM
dear op

lrn2string functions
Report Abuse
oseday is not online. oseday
Joined: 27 Aug 2008
Total Posts: 1308
27 Apr 2014 04:44 AM
Why not just use type() and tonumber()?
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
27 Apr 2014 06:34 AM
@dev:

You're right -- I should have used :changed() instead for two reasons:

1) If something other than the player modifies the text
2) It will prevent non-digits from being entered into the TextBox completely

(explanation for OP's sake)

@ose:

"use type()"
A TextBox's text will always be a string -- there's no need for type().

"and tonumber()?"
print(tonumber("123abc4"))
>nil
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
27 Apr 2014 10:05 AM
^ And that is why I prefer C.

EOS db 0x00 ;End of String Marker
Report Abuse
DragonOfWar900 is not online. DragonOfWar900
Joined: 11 May 2011
Total Posts: 1508
27 Apr 2014 11:50 AM
lol people, thanks for helping me fix my script. I wasn't actually asking to you guys to fix my script, i was only divulging my "Achievement", if i was asking you guys to fix my script, i would've put this forum in Scripting helpers forum, but still, thanks.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image