I am making an custom chat ui and it has this in a LocalScript
local m = game.Players.LocalPlayer:GetMouse()
m.KeyDown:connect(function(k)
if k == '/' then
game.Players.LocalPlayer.PlayerGui.ChatUI.Frame.Frame.TextBox:CaptureFocus()
game.Players.LocalPlayer.PlayerGui.ChatUI.Frame.Frame.TextBox.typing.Value = true
elseif k == '\r' or k == '\n' then
if game.Players.LocalPlayer.PlayerGui.ChatUI.Frame.Frame.TextBox.typing.Value == true then
game.Players.LocalPlayer:Chat(game.Players.LocalPlayer.PlayerGui.ChatUI.Frame.Frame.TextBox.Text) -- This line doesn't work
game.Players.LocalPlayer.PlayerGui.ChatUI.Frame.Frame.TextBox.typing.Value = false
game.Players.LocalPlayer.PlayerGui.ChatUI.Frame.Frame.TextBox.Text = "Click here or press '/' to chat"
end
end
end)
Now... how do I make the game.Players.LocalPlayer:Chat() work?
In an normal Script I have:
local chatstorage = game.Workspace.ChatStorage
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
local chat = Instance.new('Folder', chatstorage)
local msgVal = Instance.new('StringValue', chat)
msgVal.Name = 'Message'
msgVal.Value = plr.Name..': '..msg
local colVal = Instance.new('Color3Value', chat)
colVal.Name = 'Color'
colVal.Value = Color3.new(math.random(255)/255,math.random(255)/255,math.random(255)/255)
end)
end)
but it won't fire the plr.Chatted when I use the game.Players.LocalPlayer:Chat() in a LocalScript. How to fix this?

2 comments
I can't think of a great solution, but maybe instead of using plr.Chatted you can set up a remote event that fires from the local script when you chat
mouse.KeyDown is deprecated, and so is the second argument of Instance.new, and please use variables, don't repeat
game.Players.LocalPlayer, and the fact that you need to check if the key pressed was carriage return or a newline ('\r', '\n') is disgusting, don't ever hurt my eyes ever again