I've created a chat for in game, but the problem is that the focus is never lost on the button after they click on it or press "/" to type, so they can not move around or anything because the keys show up in the chat. Anyone know why?
wait() local storage = game.ReplicatedStorage local players = game.Players local remote = storage.ChatRemote local httpservice = game:GetService("HttpService") local ChatBox = script.Parent.ChatFrame.ChatBox local ChatFrame = ChatBox.Parent local player = game.Players.LocalPlayer local Mouse = player:GetMouse() local ChatText = ChatBox.EnterChat local Chat = ChatFrame.T1 local Settings = { chatkey = "/", Focus = false, chatboxtext = [[Press "/" or Click here to chat]], ChatLife = math.huge, ChatMax = 8 } game:GetService("StarterGui"):SetCoreGuiEnabled("Chat",false) ChatText.Text = Settings.chatboxtext function Chatted(player,message,color) local NewChat = Chat:Clone() NewChat.Visible = true if player.Name == "RockerCaleb1234" or player.Name == "devHoodie" then NewChat.Text = "{Owner}["..player.Name.."]: "..message elseif player.Name == "AlteringEgos" then NewChat.Text = "{Tester}["..player.Name.."}: "..message else NewChat.Text = "["..player.Name.."]: "..message end NewChat.TextColor3 = color NewChat.Name = player.Name for i,c in next,ChatFrame:GetChildren() do if c.Name ~= ChatBox.Name and c.Name ~= Chat.Name then c.Position = c.Position - UDim2.new(0,0,0.125,0) if c.Position.Y.Scale < 0 then c:Destroy() end end end NewChat.Parent = ChatFrame NewChat.Position = UDim2.new(0,0,.875,0) game:GetService("Debris"):AddItem(NewChat,Settings.ChatLife) end Mouse.KeyUp:connect(function(key) if key == Settings.chatkey then ChatText.Text = "" end ChatText:CaptureFocus() end) ChatText.FocusLost:connect(function(entered) if not entered and Settings.Focus then ChatText.Text = Settings.chatboxtext elseif entered then if ChatText.Text == "" then ChatText.Text = Settings.chatboxtext else remote:FireServer(ChatText.Text) end end end) remote.OnClientEvent:connect(function(player,message,color) Chatted(player,message,color) end)
In the function on line 49, you have ChatText:CaptureFocus() outside of the if statement. As a result, it fires (and captures the focus) whenever any key is released. Try putting it within the if statement:
Mouse.KeyUp:connect(function(key) if key == Settings.chatkey then ChatText.Text = "" ChatText:CaptureFocus() end end)
Hope this helps.