Help me with code (Textbox, Values, etc.)

I have this problem - I need to make sure that when writing text in a field, it is saved as a separate value after the focus is completed, but the value “Text” is always empty, even when entering numbers/text

Im noobie to working with Roblox Lua code, and I don’t know the reason for this, I couldn’t find information about it on the Internet

one of the codes that just uses the contents of the text box:

local textBox = script.Parent

local replicatedStorage = game:GetService("ReplicatedStorage")

local ItemIDValue = replicatedStorage:FindFirstChild("ItemID") or Instance.new("IntValue")
ItemIDValue.Name = "ItemID"
ItemIDValue.Parent = replicatedStorage


function SaveTextToItemID()
	local inputText = textBox.Text


	local numericValue = tonumber(inputText)

	if numericValue then
		ItemIDValue.Value = numericValue
		print("Changed Item ID: " .. numericValue)
	else
		print("ItemID Error")
	end
end

if textBox then
	textBox.FocusLost:Connect(function()
		SaveTextToItemID()
	end)
end

Try this:

local textBox = script.Parent

local replicatedStorage = game:GetService("ReplicatedStorage")

local ItemIDValue = replicatedStorage:FindFirstChild("ItemID") or Instance.new("IntValue")
ItemIDValue.Name = "ItemID"
ItemIDValue.Parent = replicatedStorage

local function SaveTextToItemID(text: string)
	local inputText = text
    print(inputText)

	local numericValue = tonumber(inputText)

	if numericValue then
		ItemIDValue.Value = numericValue
		print("Changed Item ID: " .. numericValue)
	else
		print("ItemID Error")
	end
end

if textBox then
	textBox.FocusLost:Connect(function()
		SaveTextToItemID(textBox.Text)
	end)
end

not working too. maybe the problem is not in the code but in the text box, since even my test script for displaying the content says that the field is empty

ima so dumb - i checked the status of the GUI using a simple script, and checking the textbox that was on the place, and not the local player

Thank for helping

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