Certain numbers won't pass through Textbox

Hi! I’m having trouble with this script. It works fine but whenever I enter the numbers 36-99 it won’t pass through and it would just return nothing, am I missing something here?

I can type 1-35 and 100-350 but not 36-99.

Help are appreciated!

local player = game.Players.LocalPlayer
local GUI = player.PlayerGui.FLY_GUI
local TextBox = GUI.MainFrame.TextBox
local CurrentPower = GUI.MainFrame.CurrentPower.TextLabel
local Tool = script.Parent
player:SetAttribute("FlyPower", 50)

CurrentPower.Text = "Current Power: "..player:GetAttribute("FlyPower")
Tool.Equipped:Connect(function()
GUI.Enabled = true
end)

Tool.Unequipped:Connect(function()
GUI.Enabled = false

end)

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	TextBox.Text = TextBox.Text:gsub("%D", "")
end)

TextBox.FocusLost:Connect(function()
	if TextBox.Text > tostring(350) or TextBox.Text == tostring(0) then 
		TextBox.Text = ""
		return
	end
	if TextBox.Text <= tostring(350) then
		player:SetAttribute("FlyPower", TextBox.Text)
		CurrentPower.Text = "Current Power: "..player:GetAttribute("FlyPower")
	end
end)

This may be unrelated but didn’t know you could use greater than or less than on string

Instead it should be like this

tonumber(TextBox.Text) > 350

Do you think that will make a difference with the trouble im having? Also, that is cool! I didn’t think of that.

Yeah, I believe so, what your code is doing is comparing either the amount of characters in the 350, so 3 or it’s comparing them by there ASCII table value.

So instead make the TextBox.Text into a number instead of making the numbers into a string.

Works! Thank you so much for your help! I would’ve never thought of this method. Thank you again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.