Radio messages still send even if message is empty

I’ve tried multiple ways to try and fix this, but none of them work. I’ve tried msg.Text ~= “” yet it still doesn’t work.

uis.InputBegan:Connect(function(key, gpe)
	if key.KeyCode == Enum.KeyCode.Return then
		local msg = pui.RadioUI.Main.ChatFrame.TextBox
		if #msg.Text > 0 then
			if radioon == true then
				print(tostring(radioon))
				rs.Events.RadioMessage:FireServer(msg.Text, "broadcast")
				pui.RadioUI.Main.ChatFrame.TextBox:ReleaseFocus()
				pui.RadioUI.Main.ChatFrame.TextBox.Text = ""
			else
				print(tostring(radioon))
				rs.Events.RadioMessage:FireServer(msg.Text, "proximity")
				pui.RadioUI.Main.ChatFrame.TextBox:ReleaseFocus()
				pui.RadioUI.Main.ChatFrame.TextBox.Text = ""
			end
		else
			error("message cannot be empty")
		end
	end
end)

image

i dont know what i did here but it works

uis.InputBegan:Connect(function(key, gpe)
	if key.KeyCode == Enum.KeyCode.Return then
		local msg = pui.RadioUI.Main.ChatFrame.TextBox
		if string.gsub(msg, "[ 	]+", "") ~= "" then
			-- removes tabs and spaces
			if radioon == true then
				print(tostring(radioon))
				rs.Events.RadioMessage:FireServer(msg.Text, "broadcast")
				pui.RadioUI.Main.ChatFrame.TextBox:ReleaseFocus()
				pui.RadioUI.Main.ChatFrame.TextBox.Text = ""
			else
				print(tostring(radioon))
				rs.Events.RadioMessage:FireServer(msg.Text, "proximity")
				pui.RadioUI.Main.ChatFrame.TextBox:ReleaseFocus()
				pui.RadioUI.Main.ChatFrame.TextBox.Text = ""
			end
		else
			error("message cannot be empty")
		end
	end
end)

try gsub to remove tabs and spaces

It still does it.
image

replace #msg.Text with string.len(msg.Text) > 0, I don’t think # works on strings.

I got this line of code from another scripter once, it should help you as it has helped me:

if not msg.Text:match("^%s*$") then
    -- Rest of the code here
end
print(#"Text") --> 4

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