Reason behind question: I am currently coding a Chat-like GUI that which will enter in strings, characters, and then display the message, however, UserInputService keeps on error-ring, as I have never used it before, what makes it harder is, the ROBLOX Wiki has the Documentary, however, it does not include an example code sadly.
The Output keeps saying InputObject 18:13:31.806 - Players.Player1.PlayerGui.Chat.MainScript:13: attempt to concatenate local 'k2' (a userdata value) 18:13:31.807 - Stack Begin 18:13:31.809 - Script 'Players.Player1.PlayerGui.Chat.MainScript', Line 13 18:13:31.809 - Stack End, but, because I don't know how to properly code this, I knew something like this would happen, also, yes, I have looked up if there were questions like this; There were, however, they did not explain anything related to my problem of doing a Chat-like GUI, so, that information didn't really help me when I was developing this code.
This is the code I am using [Keep in mind: I forgot to tab the code while writing it, so, please excuse me if I missed any tabs];
repeat wait() until game.Players.LocalPlayer
local plr = game.Players.LocalPlayer;
repeat wait() until plr.Character and plr.Character:FindFirstChild("Head")
local m = plr:GetMouse(); local head = plr.Character['Head'];
repeat wait() until game:GetService("Chat") and script.Parent:FindFirstChild("Txt")
local Chat = game:GetService("Chat"); local Started = false; local Txt = script.Parent['Txt'];
m.KeyDown:connect(function(k)
if k:lower() == '/' then
if not Started then Started = true
EVENT = game:GetService("UserInputService").InputBegan:connect(function(k2) print(k2)
if not Started then return end
if k2 == Enum.KeyCode.I then
k2 = "i" or "I"
elseif k2 == Enum.KeyCode.O then
k2 = "o" or "O"
end
Txt.Text = Txt.Text .. k2
if string.byte(k2) == 13 then
print(Txt.Text)
Chat:Chat(head,Txt.Text)
Txt.Text = "Type Text Here, or hit the '/' key to type"
Started = false
EVENT:disconnect()
end
end)
end
end
end)

1 comment
@Alpha; this is a very non-trivial question. In order to give you a proper answer, I would basically need to write an essay on how to make a chat system. For now, I'll leave an answer that explains how to properly use the UserInputService's events.