Help with UserInputService and chat

I’m working on a block placement system, however, I don’t want blocks to be able to be placed when the player clicks off the chat GUI instead of sending the message. Is there any way to achieve this in a basic UserInputService function?

I am already using gameProcessedEvent, which is preventing the same from happening while chatting or while hovering over GUI.

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then
	    return	
    end
    --placement script
end

This is a little bit of a hacky way to do it, and I’ve no doubt there’s more intelligent ways of doing this, but you could calculate the position of the chatbox, and the pixels it occupies on the screen. You could then check if Mouse.X and Mouse.Y are outside the chatbox.

You can read the Chat’s AbsoluteSize and AbsolutePosition values by referring to LocalPlayer.PlayerGui.Chat.Frame

Thank you, but what I meant exactly was when the player clicks off the chat after entering it to disable the GUI. They can place normally until they start typing in chat, then when they click off, that one click will not allow them to place blocks, but every click afterwards will.

In that case, I think maybe you can do the opposite of what I initially suggested

For example:
On MouseButton1, check if the chat’s Frame Visible property is true, and if the Mouse.X and Mouse.Y properties both are outside the chatbox. if both requirements are met, enable block placing?

I hope that makes sense

Utilize UserInputService.TextBoxFocused and UserInputService.TextBoxFocusReleased to track when a person is typing in a TextBox, and if the TextBox just lost focus, then you can tell that it was a TextBox and not place the block.

2 Likes

Thank you! UserInputService.TextBoxFocused was not actually necessary; I just had to switch a variable to true when UserInputService.TextBoxFocusReleased was fired, then add a conditional that would set it to false if it were true and place a block if it were false.

1 Like