Hi! I am making a custom ChatBot but there is one but in my script:
local chatInput = script.Parent:WaitForChild("Input")
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local ChannelValue = player:WaitForChild("ChannelValue", 8)
local DirectMessage = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("ChatBotMessage")
local CommandEvents = game.ReplicatedStorage:WaitForChild("ChatCommandEvents")
local cooldown = 0.05
local isCoolingDown = false
local player = game.Players.LocalPlayer
local admin
if player.Name == "Actulurus" then admin = true else admin = false end
uis.InputEnded:Connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.Slash and not gameProcessed then
chatInput:CaptureFocus()
end
end)
chatInput.FocusLost:Connect(function(enterPressed)
if not enterPressed then return end
local input = chatInput.Text
chatInput.Text = ""
if string.len(input) > 0 then
if isCoolingDown == true then
chatInput.Text = "Wait for cooldown to end!"
return
end
isCoolingDown = true
print(input)
DirectMessage:FireServer(input, "#ChatBot")
script.Parent.Input:CaptureFocus()
wait(cooldown)
isCoolingDown = false
end
end)
CommandEvents.Sudo.OnClientEvent:Connect(function(msg)
DirectMessage:FireServer(msg)
end)
When I send my first message, the TextBox captures focus again but there is a space instead of no text.
When I set it equal to āā it still contained a space. I could see the entire message āoffsetā by one character at the start (which was the space")
Itās pretty much the same thing, clearing the text when the player clicks on the TextBox again, or after they press enter/click away. Heās clearing the text when the focus is lost, so that the TextBox is empty when the player clicks on it again vs the TextBox clearing itself when the player clicks on it.
Also, it works perfectly fine when i click away and then click on the TextBox again. The problem is i want to capture focus every time we send a message.