How to detect if textbox is numbers?

Hello, another post again i know but i would like know how to detect if textbox is a number once again here is this script

local TextBox = script.Parent.Input

script.Parent.TextButton.MouseButton1Click:Connect(function()
	local text = "rbxassetid://"..tostring(TextBox.Text)
	script.Parent.Parent.Parent.Parent.Image = text
end)

il reply fast as soon! if u get it
image
when clicking done I want it detect if its a number or not

2 Likes

You could use a function called tonumber().

That would be:

if tonumber(TextBox.Text) then
    print("is number")
end

(format on mobile)

2 Likes

cool thanks man but how do i make sure not allow the imagelabel to change like else?

1 Like

So you want to make sure the player has finished editing the text?

If so, the connection you should make is textBox.FocusLost

1 Like

yeah like that maybe or yeah that

1 Like
TextBox.FocusLost:Connect(function()

    -- code goes here

end)
1 Like

Example of a input open all the time … update then FireServer when used.

local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage.SeedEvent
local seed 

script.Parent.FocusLost:Connect(function(enter)
	seed = script.Parent.Text
	event:FireServer(seed)
end)
1 Like
TextBox.FocusLost:Connect(function()
	if tonumber(TextBox.Text) then
		print("is number")
	end
end)

like this? and the else what about that

1 Like
local TextBox = script.Parent.Input

script.Parent.TextButton.MouseButton1Click:Connect(function()
	if tonumber(TextBox.Text) then
		local text = "rbxassetid://"..tostring(TextBox.Text)
		script.Parent.Parent.Parent.Parent.Image = text
	else
		print("is letter")
	end
end)

I think I figured it out?

1 Like

i have issue


the image didnt show when I changed the script to this :

local TextBox = script.Parent.Input
local Detecter = script.Parent.TextLabel

script.Parent.TextButton.MouseButton1Click:Connect(function()
	if tonumber(TextBox.Text) then
		local text = "rbxassetid://"..tostring(TextBox.Text)
		script.Parent.Parent.Parent.Parent.Image = text
		print("is number")
		Detecter.TextColor3 = Color3.new(0.141176, 1, 0.00784314)
		Detecter.Text = "Done!"
		wait(1)
		Detecter.TextColor3 = Color3.new(1, 1, 1)
		Detecter.Text = "Use images pls!"
		script.Parent.Visible = false
	else
		print("is letter")
		Detecter.TextColor3 = Color3.new(1, 0, 0.0156863)
		Detecter.Text = "Not a number!"
		wait(1)
		Detecter.TextColor3 = Color3.new(1, 1, 1)
		Detecter.Text = "Use images pls!"
	end
end)

it only shows if i find the decal image not the asset image can you tell why?