Hi, i’m trying to check if a TextBox.Text string only contains numbers… Can anyone help me with this?
script.Parent.MouseButton1Click:Connect(function()
local Player = script.parent.parent.parent.parent.parent.parent.parent.parent
local Amount = Player.PlayerGui.Menus.Vault.Main.Holder.Amount.TextBox.Text
if Amount... then
else
end
end)
My script is above.
I tryed using tonumber() but that didn’t work.
script.Parent.MouseButton1Click:Connect(function()
local Player = script.parent.parent.parent.parent.parent.parent.parent.parent
local Amount = Player.PlayerGui.Menus.Vault.Main.Holder.Amount.TextBox.Text
if (Amount:match("%W")) then
print("1")
else
print("2")
end
end)
but no matter what it just prints 2 if its all numbers, numbers and letters or just letters
The best approach would be tonumber, how did you set out the code with tonumber? I’ve just tried this and it worked:
script.Parent.Activated:Connect(function()
local Amount = script.Parent.Parent.TextBox.Text
if tonumber(Amount) then
print(Amount)
else
return
end
end)
script.Parent.MouseButton1Click:Connect(function()
local Player = script.parent.parent.parent.parent.parent.parent.parent.parent
local Amount = Player.PlayerGui.Menus.Vault.Main.Holder.Amount.TextBox.Text
if tonumber(Amount) then
print(Amount)
else
print("no")
end
end)
still prints “no” and btw its serversided idk if that makes a difference
this is the same way i tryed it before