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)