On screen keyboard not sending to chat

Okay so i’m creating my own VR game (and because i suck i use Nexus VR) But the problem is that you can’t use the chat without walking towards your keyboard and then typing. So i was trying to make a keyboard that enables on a press of a button and lets you type in game (nothing fancy, just something simple)

But i’m stuck at that it wont send the message to the chat. I was thinking of using a custom chat service but that i would be stuck with getting filtering on it and thats just a hassle i don’t wanna deal with.

I don’t get an error or anything so i don’t really know exactly what’s wrong. I’ve showed it to a friend aswell and he couldn’t find anything wrong with it too

[ Given that there is a solution i hope that if there is ever someone having the same problems will find this also very helpful! ]

-- Get the existing TextBox
local textBox = script.Parent.TextBox

-- Define the key labels for each row
local keyLabels = {
	{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Backspace"},
	{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "Enter"},
	{"a", "s", "d", "f", "g", "h", "j", "k", "l", "!", "'"},
	{"z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "?", "Space"}
}

-- Create the buttons for each key label
local buttonSize = UDim2.new(0, 40, 0, 40) -- Adjust the button size as needed
local buttonSpacing = 5 -- Adjust the button spacing as needed

local yOffset = 0
local maxXOffset = 0

for rowIndex, rowKeys in ipairs(keyLabels) do
	local xOffset = 0

	for _, keyLabel in ipairs(rowKeys) do
		local button = Instance.new("TextButton")
		button.Name = keyLabel
		button.Size = buttonSize
		button.Position = UDim2.new(0, xOffset, 0, yOffset)
		button.Text = keyLabel
		button.Parent = script.Parent

		button.MouseButton1Click:Connect(function()
			if keyLabel == "Backspace" then
				local text = textBox.Text
				textBox.Text = text:sub(1, #text - 1)
			elseif keyLabel == "Enter" then
				local text = textBox.Text
				textBox.Text = "" -- Clear the textbox content
                      -- Yes I've tried switching this making it so it fires it to the chat BEFORE it removes the text. But that only seems to Break the textbox
				-- Send the message in the chat using SayMessageRequest
				local player = game.Players.LocalPlayer
				local channelId = "All"
				local chatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

				chatService:Chat(player, text, channelId)
			elseif keyLabel == "Space" then
				textBox.Text = textBox.Text .. " "
			else
				textBox.Text = textBox.Text .. keyLabel
			end
		end)

		xOffset = xOffset + buttonSize.X.Offset + buttonSpacing
	end

	maxXOffset = math.max(maxXOffset, xOffset - buttonSpacing)
	yOffset = yOffset + buttonSize.Y.Offset + buttonSpacing
end

-- Adjust the size of the frame
script.Parent.Size = UDim2.new(0, maxXOffset, 0, yOffset - buttonSpacing)

image

image

1 Like

r u using the new chat service because you can just use the remote event used to send messages

i’ve not even worked once with the new chat service lol. seems like i have to as i tried just a standard message from local script to client sided to the chat also dont work. either im stupid or it just doesnt work like it used to

You can’t access ServerScriptService from the Client, hope this helps.

1 Like

Some background to the keyboard would be nice.

I have a grey background for it but have transparency on 1

yeah i’ve tried with sending a remote event but it showed the same results

Here.

local ChatService = game:GetService("TextChatService") -- Get TextChatService
local Channel = ChatService:WaitForChild("TextChannels") -- Wait for Channels to be created
Channel = Channel:WaitForChild("RBXGeneral") -- Reference the target channel ("All" == "RBXGeneral")

-- Get the existing TextBox
local textBox = script.Parent.TextBox

-- Define the key labels for each row
local keyLabels = {
	{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Backspace"},
	{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "Enter"},
	{"a", "s", "d", "f", "g", "h", "j", "k", "l", "!", "'"},
	{"z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "?", "Space"}
}

-- Create the buttons for each key label
local buttonSize = UDim2.new(0, 40, 0, 40) -- Adjust the button size as needed
local buttonSpacing = 5 -- Adjust the button spacing as needed

local yOffset = 0
local maxXOffset = 0

for rowIndex, rowKeys in ipairs(keyLabels) do
	local xOffset = 0

	for _, keyLabel in ipairs(rowKeys) do
		local button = Instance.new("TextButton")
		button.Name = keyLabel
		button.Size = buttonSize
		button.Position = UDim2.new(0, xOffset, 0, yOffset)
		button.Text = keyLabel
		button.Parent = script.Parent

		button.MouseButton1Click:Connect(function()
			if keyLabel == "Backspace" then
				local text = textBox.Text
				textBox.Text = text:sub(1, #text - 1)
			elseif keyLabel == "Enter" then
				local text = textBox.Text
				textBox.Text = ""

				Channel:SendAsync(text) -- Use SendAsync to send the text.
			elseif keyLabel == "Space" then
				textBox.Text = textBox.Text .. " "
			else
				textBox.Text = textBox.Text .. keyLabel
			end
		end)

		xOffset = xOffset + buttonSize.X.Offset + buttonSpacing
	end

	maxXOffset = math.max(maxXOffset, xOffset - buttonSpacing)
	yOffset = yOffset + buttonSize.Y.Offset + buttonSpacing
end

-- Adjust the size of the frame
script.Parent.Size = UDim2.new(0, maxXOffset, 0, yOffset - buttonSpacing)
1 Like

thank you so much!!
it works perfectly

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