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

How Do I know If a Value(which comes from a textbox) is a string or not?

Asked by 5 years ago

~~~~~~~~~~~~~~~~~ --I tried local uis = game:GetService("UserInputService") local byteFlag = 0 local xByte = 0 local yByte = 0 uis.InputBegan:Connect(function(key) if byteFlag == 1 then if script.Parent.Text then xByte = script.Parent.Text byteFlag = 2 print(xByte) end end

01if byteFlag == 2 then
02    if key.KeyCode == Enum.KeyCode.Return then
03        local yByte = script.Parent.Text
04        byteFlag = 3
05        print(yByte)
06    end
07end
08 
09if byteFlag == 3 then
10    script.Parent.Parent.Position.X = script.Parent.Parent.Position.X + xByte
11    script.Parent.Parent.Position.Y = script.Parent.Parent.Position.Y + yByte
12    byteFlag = 0
13end
14 
15if key.KeyCode == Enum.KeyCode.Return and byteFlag == 0 then
View all 21 lines...

end) --Im fairly new to this kinda coding Im tryna make a admin for the game, And I cant get pass this. ~~~~~~~~~~~~~~~~~**** I really need help I tried to search this on the internet but 0 results.

0
the full code is at https://pastebin.com/LsLGJHQY Yesil_Hiyar 5 — 5y

3 answers

Log in to vote
1
Answered by
Abandion 118
5 years ago

A textbox input will always be a string. You can check to see if the input can be formatted as a number with tonumber, like so

1string1 = "56"
2string2 = "hello"
3 
4print(tonumber(string1)) --Will return 56 formatted as a number
5print(tonumber(string2)) --Will return nil as "hello" cannot be formatted as a number
Ad
Log in to vote
0
Answered by 5 years ago

same thing as that guy.

1string = "pie"
2if not tonumber(string) then
3 
4            print("no numbers!")
5else
6print("there is a number in there!")
7        end

output: no numbers!

1string = "64 carrots"
2if not tonumber(string) then
3 
4            print("no numbers!")
5else
6print("there is a number in there!")
7        end

output: "there is a number in there!"

Log in to vote
0
Answered by 5 years ago

The above methods are a way to figure things out but If I recall correctly, you can use TypeOf to find the type of value of something like so:

1local string = "String"
2local number = 1
3local boolean = false
4 
5print(typeof(string))
6print(typeof(number))
7print(typeof(boolean))
  1. string
  2. number
  3. boolean

Then you can do conditional statements to figure things out;

1local Text = "Hello"
2 
3if typeof(Text) == "string" then
4    print("It's a string")
5end

Hope this helped!

Answer this question