Need help with in-game chatlogs command

Hello! My name is Kyle and I’m currently have trouble with an in-game chat logs command. I would like to know how to get started, and how I would store the chat from plr.Chatted. I’m hoping to make it so only certain people can use chatlogs as well. Can I please get some help on where to start?

First you need to define which players can access the chatlogs, you can do this with a table:

local Admins = {"PlayerUsername"} -- Using Id is better than username but this should do for now.

To only make Admins be able to access it you can do this:

local Admins = {"PlayerUsername"} -- Players who can access chat logs
local ScreenGui -- Define.

game:GetService("Players").PlayerAdded:Connect(function(Player)
    if table.find(Admins, Player.Name) then -- Checks if the Player's name is in the table
       ScreenGui:Clone().Parent = Player.PlayerGui -- Clones the gui and moves to the Player's PlayerGui
    end
end)

And to add a chat log everytime you can clone a textlabel everytime a player chats and move it down the previous one (Probably not the most efficient way though:

local Admins = {"PlayerUsername"} -- Players who can access chat logs
local ScreenGui -- Define.
local ChatLog -- Define.
local lastChatlogPos = ChatLog.Position -- Gets the ChatLog TextLabel's Position
local ChatLogOffset = UDim2.new(0, 0, 0.07, 0) -- This is the offset between each chatlog

game:GetService("Players").PlayerAdded:Connect(function(Player)
    if table.find(Admins, Player.Name) then -- Checks if the Player's name is in the table
       ScreenGui:Clone().Parent = Player.PlayerGui -- Clones the gui and moves to the Player's PlayerGui

        Player.Chatted:Connect(function(Message) -- Detects when a player chats
            print(string.format("[%s]: %s", Player.Name, Message)) -- formats the string and prints the message
            local NewChat = ChatLog:Clone() -- clones the last chatlog
            NewChat.Position = lastChatlogPos + ChatLogOffset -- Positions the new chatlog
            NewChat.Text = string.format("[%s]: %s", Player.Name, Message) -- sets the text of the new chatlog
            lastChatlogPos = NewChat.Position -- Sets the lastchatlogpos to the New chatlog's pos
        end)
    end
end)

This probably isn’t the best way but it should give you an idea of what you can do.

1 Like

Thank you! This helped a lot! [Chatminimum]

1 Like