I am having issues deleting messages that are not recieved from the server in the chat channel “Logs”, do not edit the staff one though.
Current code I have:
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local logWelcomeEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Other"):WaitForChild("LogEvent")
local staffWelcomeEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Other"):WaitForChild("StaffEvent")
local function createStaffChannel()
local staffChannel = Instance.new("TextChannel")
staffChannel.Name = "Staff"
staffChannel.Parent = TextChatService:WaitForChild("TextChannels")
end
local function createLogsChannel()
local logsChannel = Instance.new("TextChannel")
logsChannel.Name = "Logs"
logsChannel.Parent = TextChatService:WaitForChild("TextChannels")
logsChannel.MessageReceived:Connect(function(message)
local source = message.TextSource
if source then
print("Message received from:", source.Name)
if source:IsA("Player") then
print("Deleting message from player:", source.Name)
message:Destroy()
else
print("Message is not from a player:", source.Name)
end
else
print("Message source is nil")
end
end)
end
local function addPlayerToStaffChannel(player)
if player:GetRankInGroup(8423759) >= 6 then
local staffChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Staff")
if staffChannel then
staffChannel:AddUserAsync(player.UserId)
staffWelcomeEvent:FireClient(player, "Hello %s! Only staff can see and type in this channel.")
end
end
end
local function addPlayerToLogsChannel(player)
if player:GetRankInGroup(8423759) >= 6 then
local logsChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs")
if logsChannel then
local textSource = logsChannel:AddUserAsync(player.UserId)
textSource.CanSend = false
logWelcomeEvent:FireClient(player, "Hello %s, in this channel (logs) you are not allowed to send messages. These are for flagging events and other actions to assist in moderation.")
end
end
end
createStaffChannel()
createLogsChannel()
Players.PlayerAdded:Connect(function(player)
addPlayerToStaffChannel(player)
addPlayerToLogsChannel(player)
end)
for _, player in Players:GetPlayers() do
addPlayerToStaffChannel(player)
addPlayerToLogsChannel(player)
end
(by the way, yes I have debugged it and nothing has printed.)
The text channel “Logs” does get created. Not sure why it won’t work.
TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs").OnIncomingMessage = function(message)
local source = message.TextSource
if source then
if source:IsA("Player") then
message:Destroy()
end
end
end
I have a new script now from trialing a little bit.
local logsChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs")
logsChannel.OnIncomingMessage = function(message)
local properties = Instance.new("TextChatMessageProperties")
properties.Text = message.Text
if message.TextSource then
local sourcePlayer = Players:GetPlayerByUserId(message.TextSource.UserId)
if sourcePlayer then
return nil
end
end
return properties
end
I just read through the documentation (that the other guy sent) and TextSource is the user’s name and information on things like their permission to the channel, etc.
TextSource is the data that represents a speaker in a TextChannel.
I am attempting to figure it out, please have patience.
No. This is client sided now. The one before has had this part taken out:
And put in a client sided script:
local logsChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs")
logsChannel.OnIncomingMessage = function(message)
local properties = Instance.new("TextChatMessageProperties")
properties.Text = message.Text
if message.TextSource then
local sourcePlayer = Players:GetPlayerByUserId(message.TextSource.UserId)
if sourcePlayer then
return nil
end
end
return properties
end