How to disable certain letters in chat?

Hey! I have a question that i dont know if possible or not.
The question: is it possible so player cant type a certain letter(s) in chat?

I know you can use event after player chatted and censor the letter(s). But i want it the other way where u cant even type the letter in.

Thank you.

If it didnt make sense, answer more question so i can answer them! Feel free to.

I don’t think this is possible unless you make a custom chat window.

1 Like

It should be possible, depending on the chat system you are using.

Are you using legacy or the new one?

1 Like
1 Like

I can use anything just to make it work.

Thanks, i`ll look into that. But thats not exactly what im looking for. I want so if you press a button it doesnt type in.

Could you explain why you want this behaviour?

If it is because something else in your game uses that letter, you can use ContextActionService or the GameProcessedEvent passed when using UserInputService’s events (to prevent the action in your game from running when the player is chatting)

Using ContextActionService:BindActionAtPriority(), you can bind an action to a keybind, and other actions using that keybind, with a lower priority, will be overwritten/disabled

Otherwise, you can code that behaviour if you fork the LegacyChat, in the ChatBar Module, on line 188 and down


image

The chat seems to detect inputs from Textbox.Changed. You can probably check the last character of Textbox.Text, and remove it if it is one of the letters you want to block. Or you could do a string.gsub on Textbox.Text as a whole, I doubt performance would be a concern

I highly doubt this is possible with TextChatService. You probably are able to remove letters from messages, but not prevent them from being typed

3 Likes

im making kinda a keyboard simulator thing where u need to unlock keys and you cant type a certain letter until you unlock it. it shouldnt be necessary that, i can do it like that: player chats, adn then i delete characters after he types, but thats not interesting. so i wanted to find out how do to it the other way

1 Like

thank you for the explanation!!! forgot to check these scripts.

1 Like
self.TextBoxConnections.TextBoxChanged = TextBox.Changed:connect(function(prop)
		if prop == "AbsoluteSize" then
			self:CalculateSize()
			return
		end

		if prop ~= "Text" then
			return
		end
		
		local DisallowedCharacters = {"a","b","c"} -- Get this from your other code :P
		local StringLenght = #TextBox.Text
		
		if table.find(DisallowedCharacters,string.sub(TextBox.Text, StringLenght, StringLenght)) then
			TextBox.Text = string.sub(TextBox.Text, 1 , StringLenght -1)
			return -- This will trigger TextBox.Changed, so return
		end

		self:CalculateSize()

		if utf8.len(utf8.nfcnormalize(TextBox.Text)) > ChatSettings.MaximumMessageLength then
			TextBox.Text = self.PreviousText
		else
			self.PreviousText = TextBox.Text
		end

		if not self.InCustomState then
			local customState = self.CommandProcessor:ProcessInProgressChatMessage(TextBox.Text, self.ChatWindow, self)
			if customState then
				self.InCustomState = true
				self.CustomState = customState
			end
		else
			self.CustomState:TextUpdated()
		end
	end)

The code can look something like this, it only works with single character strings, but knowing your use case, this is probably fine


While forking the chat, you might be interested in this: Customized Chat, Giving a second life to the old beloved chat. It’s a modified version of the legacy chat, with some changes to make it look more modern, and some bug fixes

1 Like

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