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 4 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

if byteFlag == 2 then
    if key.KeyCode == Enum.KeyCode.Return then
        local yByte = script.Parent.Text
        byteFlag = 3
        print(yByte)
    end
end

if byteFlag == 3 then
    script.Parent.Parent.Position.X = script.Parent.Parent.Position.X + xByte
    script.Parent.Parent.Position.Y = script.Parent.Parent.Position.Y + yByte
    byteFlag = 0
end

if key.KeyCode == Enum.KeyCode.Return and byteFlag == 0 then
    --Blah blah blah code stuff
    if string.lower(script.Parent.Text) == "move" then
        byteFlag = 1
    end
    print("Yikesss")
end

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 — 4y

3 answers

Log in to vote
1
Answered by
Abandion 118
4 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

string1 = "56"
string2 = "hello"

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

same thing as that guy.

string = "pie"
if not tonumber(string) then

            print("no numbers!")
else
print("there is a number in there!")
        end

output: no numbers!


string = "64 carrots" if not tonumber(string) then print("no numbers!") else print("there is a number in there!") end

output: "there is a number in there!"

Log in to vote
0
Answered by 4 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:

local string = "String"
local number = 1
local boolean = false

print(typeof(string))
print(typeof(number))
print(typeof(boolean))
  1. string
  2. number
  3. boolean

Then you can do conditional statements to figure things out;

local Text = "Hello"

if typeof(Text) == "string" then
    print("It's a string")
end

Hope this helped!

Answer this question