There is a team in my game where they are forced to use TeamChat, and I want to delete the messages they send if they aren’t sent in the teamchat channel.
It hasn’t been working so i tried using print() to find the errors, but nothing appears in the console
Here’s the script:
local Channels = TextChatService:WaitForChild("TextChannels"):GetChildren()
for _, Channel in pairs(Channels) do
print(Channel.Name)
Channel.ShouldDeliverCallback = function(message, messageSource)
-- If message has a source
if message.TextSource then
local sender = Players:GetPlayerByUserId(messageSource.UserId)
-- Get the player that sent the message
if sender then
print(sender.Name)
-- Check if the player is in the forced team
if sender.Team.Name == forcedTeam.Name then
print(sender.Name.."'s team has forced teamchat")
if Channel.Name ~= "RBXTeamReally red" then
print("message not sent in teamchat. returning false")
return false
end
end
print("message returning true")
return true
end
end
end
end
That means that the print statements inside your ShouldDeliverCallback function are not firing. So perhaps the function is not being called at all? Try using a print statement straight after the function is being used print("Call-back activated") to see if that works. If that works, then perhaps messageSource is not being obtained or used properly, messageSource.UserId may be nill or invalid preventing the rest of your code from executing. Go line by line and make sure each line works.
Where did you have the local script positioned (what is the highest class that it’s contained in, e.g. workspace, StarterGui, ServerStorage, ReplicatedStorage etc.)?
Local scripts can only run in specific places, so it’s possible that the script is in a place that it can’t be run, hence no print statements and the code doesn’t function.