I am making a custom chat and I know how to do everything except for get the event when the player presses buttons. So I have a variable called chatting and if that is true then I want to get the players keyboard input. Obviously I can use keydown but that doesnt get capitalized letters or any of these: -;'± etc.
Basically I just want an event for when a player presses a key and it gives me the key that they pressed.If theres no event then I need a way to figure the key out because even with string.byte(key) it doesn’t get the capitalized letter.
Use the UserInputService to detect an input when a key is pressed.
Example:
local UIS = game:GetService("UserInputService");
UIS.InputBegan:Connect(function(input)
-- Change "F" to whatever your input is.
if input.KeyCode == Enum.KeyCode.F then
-- Do stuff.
end
end)
Simple as that. For a chat script, make sure to account for when the player’s .Chatted event fires OR use a completely custom system and detect “slash” key inputs or “escape”/“return” inputs.
UserInputService supports both lowercase and uppercase lettering. If you need only lowercase lettering, map out your inputs in a table and match it to a string using string.lower();
Try the following:
local test = {
[Enum.KeyCode.F] = "f"
};
local returnVariable = [input];
EDIT: To detect if the key itself is lowercased, add a “leftshift”, “rightshift”, or “capslock” detection to see if the key is uppercased. I believe, since the key is an Enum, you can’t use tostring(). However, I’ve seen people use key bytes (I think it’s key bytes-basically the numbers equivalent to the key).
Make sure to filter it on the server side and with remoteevent Fire the filtered text to all clients
Event:FireAllClients(Sender,Message)
Also, when you are filtering the text make sure to use pcall() it is connected to http so it would sometimes throw error also it would be good if you add something like this in client side
if (string.len(TextBox.Text) > 2) then
Event:FireServer(TextBox.Text)
end
This checks if textbox is empty or not or if player typed more then 2 letters in it.
Does not matter if it is upper or lower it will still continue I believe.
or just do
local UIS = game:GetService("UserInputService");
UIS.InputBegan:Connect(function(input)
-- Change "F" to whatever your input is.
if string.upper(input.KeyCode) == Enum.KeyCode.F then
-- Do stuff.
end
end)
I know it will continue but I want to be able to know the difference. I want to use the KeyCode and see if the key is upper or lower case. I dont want the person to only be able to type capitals or non caps. Also I put that code in and string.upper errors
Wouldn’t recommend doing that as players could then type vertically. That’s why the built in Roblox chat censors 1 (and possibly 2, I don’t remember) letter chats.
Tbh I never thought of textbox so I spent like 4 hours making custom chat and now I realize I can make it better and I could’ve done it in like 20 minutes. Thanks