Attempt to call a nil value

Well, I’m trying to send a FireServer with the data of a TextBox converted to ToNumber, but it gives me the error of the title and I don’t know what is the reason why it gives it

FrameSizeSlots:WaitForChild("TextBox"):GetPropertyChangedSignal("Text"):Connect(function()
	FrameSizeSlots:WaitForChild("TextBox").Text = FrameSizeSlots:WaitForChild("TextBox").Text:gsub('%D+', '')
end)
FrameSizeSlots:WaitForChild("TextBox").FocusLost:Connect(function(enterPressed, inputThatCausedFocusLost)
	if enterPressed then
		local Number = tonumber(FrameSizeSlots:WaitForChild("TextBox").Text)
		ChangeDataFPSAndPing:FireServer("SlotsInventory", Number)
		FrameSizeSlots:WaitForChild("TextBox").PlaceholderText = "{0, "..Number.."},{0, "..Number.."}"
		FrameSizeSlots:WaitForChild("TextBox").Text = "{".. Number.."}"
	end
	FrameSizeSlots:WaitForChild("TextBox").Text = ""
end)
FrameSizeSlots:WaitForChild("TextBox").Focused:Connect(function()
	FrameSizeSlots:WaitForChild("TextBox").PlaceholderText = ""	
	FrameSizeSlots:WaitForChild("TextBox").Text = ""	
end)

Do this

local TextBox = FrameSizeSlots:WaitForChild("TextBox")

add this to the begenning. Don’t do :WaitForChild every time when you can use a simple variable. Also is the text a number? If not then that will happen

2 Likes

It might be including the Enter key when FocusLost is fired - you probably need to sanitize the string. Iirc, you can sanitize it by doing str:gsub("%c", "").

1 Like
local TextBox = FrameSizeSlots:WaitForChild("TextBox")

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

TextBox.FocusLost:Connect(function(enterPressed, inputThatCausedFocusLost)
	if enterPressed then --make sure you press enter to lose focus
		local Number = tonumber(TextBox.Text)
		ChangeDataFPSAndPing:FireServer("SlotsInventory", Number)
		TextBox.PlaceholderText = "{0, "..Number.."},{0, "..Number.."}"
		TextBox.Text = "{"..Number.."}"
	end
	TextBox.Text = ""
end)

TextBox.Focused:Connect(function()
	TextBox.PlaceholderText = ""	
	TextBox.Text = ""	
end)
1 Like

Just an added note but this isn’t the entire script right? Because “ChangeDataFPSAndPing” isn’t defined.

1 Like

That’s right, this is not the whole script, it is just the part I need to do the function I want.