Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Pressing Enter will not work with Custom Chat GUI. How could I fix?

So I have a Custom Chat GUI. What isn't working here is when I press enter after typing a message, it doesn't do anything. I've added a function and an if statement to detect if the Enter key was pressed. I've also added something so inside the if statement, it would execute a print command at the beginning and one after it to see if it was working, but nothing shows up in output.

local Player = game.Players.LocalPlayer
local Parent = script.Parent
local Mouse = Player:GetMouse()
local msgbar = Parent.msgbar

function EnterTriggerSend(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Return and script.Parent.msgbar:IsFocused() then
		wait()
		print "Pre-Test Successful"
		script.Parent.Parent.MsgChatFrame.chatbox6.Text = script.Parent.Parent.MsgChatFrame.chatbox5.Text
		script.Parent.Parent.MsgChatFrame.chatbox5.Text = script.Parent.Parent.MsgChatFrame.chatbox4.Text
		script.Parent.Parent.MsgChatFrame.chatbox4.Text = script.Parent.Parent.MsgChatFrame.chatbox3.Text
		script.Parent.Parent.MsgChatFrame.chatbox3.Text = script.Parent.Parent.MsgChatFrame.chatbox2.Text
		script.Parent.Parent.MsgChatFrame.chatbox2.Text = script.Parent.Parent.MsgChatFrame.chatbox1.Text
		script.Parent.Parent.MsgChatFrame.chatbox6.Text = script.Parent.msgbar.Text
		wait(0.1)
		script.Parent.msgbar:ReleaseFocus()
		script.Parent.msgbar.Text = "Tap the "/" button or click here to chat"
		print "Post-Test Successful"
		wait()
	end
end

game:GetService("UserInputService").InputBegan:connect(EnterTriggerSend)

Chat GUI

Hierarchy of GUI

2 answers

✓ Accepted answer

First of all, you need to escape your quotes so they don't actually end the string on line 18, like

script.Parent.msgbar.Text = "Tap the \"/\" button or click here to chat"

What I think the problem is, when they press return, it is already not focused. To fix this, we can use FocusLost like so

local boxes = script.Parent.Parent.MsgChatFrame

script.Parent.msgbar.FocusLost:Connect(function(enter)
	if enter then --Did the player press enter to stop focus? We don't want people to send messages by clicking on another text box!
		print "Pre-Test Successful"
	        for box = 6, 2, -1 do
			boxes['chatbox'..box].Text = boxes['chatbox..(box - 1)].Text
		end
		
	        script.Parent.Parent.MsgChatFrame.chatbox6.Text = script.Parent.msgbar.Text
		--We don't want the player to think their game is lagging, so I removed the wait.
	        script.Parent.msgbar.Text = "Tap the \"/\" button or click here to chat"
	        print "Post-Test Successful"
	end
end)

I also shortened the code a little, but I am not going to explain it unless you ask in the comments.

Hope this helps!

4 comments

0

trash

0

This only seems to edit chatbox6 with text from the msgbar. Is there a way to make it so when you also send message, chatbox6's text goes to chatbox5, chatbox5 to chatbox4, etc... ?

0

I shortened it by using the for loop. Try it out.

0

Thanks! I found out I mixed up the chatbox loop thing.

You should escape your quotes

script.Parent.msgbar.Text = "Tap the \"/\" button or click here to chat"

	local boxes = script.Parent.Parent.MsgChatFrame

	script.Parent.msgbar.FocusLost:Connect(function(enter)
	    if enter then --Did the player press enter to stop focus? We don't want people to send messages by clicking on another text box!
	        print "Pre-Test Successful"
	            for box = 6, 2, -1 do
	            boxes['chatbox'..box].Text = boxes['chatbox'..(box - 1)].Text
	        end
	 
	              script.Parent.Parent.MsgChatFrame.chatbox6.Text = script.Parent.msgbar.Text
	        --We don't want the player to think their game is lagging, so I removed the wait.
	            script.Parent.msgbar.Text = "Tap the \"/\" button or click here to chat"
	            print "Post-Test Successful"
	    end
	end)

I also shortened the code a little.

2 comments

0

This only seems to edit chatbox6 with text from the msgbar. Is there a way to make it so when you also send message, chatbox6's text goes to chatbox5, chatbox5 to chatbox4, etc... ?

0

Please explain what your code is doing, and how you fixed it. Also, you cannot call an answer "trash" and copy that answer, as that means your answer is trash, according to what you said.

This discussion is preserved as it was. New answers, comments, and votes are closed.