Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to get value from text box input?

I am trying to store a value in a NumberValue when a person types in a number in the text box and hits enter.

When the player hits enter, I want the value to be stored in the NumberValue

script.Parent.Frame.AyeInput.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		script.Parent.Frame.AyeInput.AyeInputValue.Value = script.Parent.Frame.AyeInput.Text
	end
end)

It seems like I am close, but I could be way off. The reason I want to store the value is because it will be used in another gui. I also want this to be used multiple times, so every time the player inputs a value, the value can keep changing.

Thank you.

3 comments

0

Did you make sure it is a local script? I copy and pasted the script into my game and it worked fine.

0

I tried both script and localscript and nothing seems to be happening. I put in a random numeric value in the text box, press enter, but the NumberValue doesn't change. It remains 0.

0

I don't think I should be using 'Text' in the script. When the user presses enter in the text box, I just need to save the value in the Number Value

1 answer

###This is because you can not assign a string when a number should be the property value. You'll want to wrap this in a pcall (protected call) to prevent errors in the output. Any input can be processed, such as letters. Letters are not numbers, and cannot be converted into numbers.

local success, message = pcall(function()
    script.Parent.Frame.AyeInput.AyeInputValue.Value = tonumber(script.Parent.Frame.AyeInput.Text)

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.