I’m trying to make a team chat visible to specific teams. If an Irish Raider or Civilian sends a message, it should only be visible to them. If any other team sends a message, it should be visible to only the other teams. I need help.
game.ReplicatedStorage.RadioAssets.SendMessage.OnServerEvent:Connect(function(player, message, messageType)
message = getFilteredMessage(message, player.UserId)
if messageType == "Global" then
for i, v in pairs(game.Players:GetChildren()) do
local newMessage = game.ReplicatedStorage.RadioAssets.MessageTemplate:Clone()
newMessage.Parent = v.PlayerGui.Radio.Global.Messages
newMessage.Sender.Text = string.upper(player.Name)
newMessage.Sender.TextColor3 = player.TeamColor.Color
newMessage.Content.Text = message
newMessage.Visible = false
if player.Team.Name == "Irish Raider" or player.Team.Name == "Civilian" then
if v.Team.Name == "Irish Raider" or v.Team.Name == "Civilian" then
newMessage.Visible = true
end
end
if player.Team.Name ~= "Irish Raider" or player.Team.Name ~= "Civilian" then
if v.Team.Name ~= "Irish Raider" or v.Team.Name ~= "Civilian" then
newMessage.Visible = true
end
end
end
elseif messageType == "Team" then
for i, v in pairs(game.Players:GetChildren()) do
if v.Team == player.Team then
local newMessage = game.ReplicatedStorage.RadioAssets.MessageTemplate:Clone()
newMessage.Parent = v.PlayerGui.Radio.Team.Messages
newMessage.Sender.Text = string.upper(player.Name)
newMessage.Sender.TextColor3 = player.TeamColor.Color
newMessage.Content.Text = message
end
end
end
end)
There are no errors or anything? I’d start with printing some stuff out to debug and make sure everything is what it is expected to be. Like printing out the message, and the messageType to make sure it’s what it should be. If they are, I’d add some prints along the way in the script to see where it’s possibly stopping. I don’t see anything wrong with the code just looking over it but I’m very bad at fixing things without being hands on/having access to the assets.
I put a printout to see when the message was shown, and for some reason, when all the players are in the game is says “Sent and received by military”.
game.ReplicatedStorage.RadioAssets.SendMessage.OnServerEvent:Connect(function(player, message, messageType)
message = getFilteredMessage(message, player.UserId)
if messageType == "Global" then
for i, v in pairs(game.Players:GetPlayers()) do
local newMessage = game.ReplicatedStorage.RadioAssets.MessageTemplate:Clone()
newMessage.Parent = v.PlayerGui.Radio.Global.Messages
newMessage.Sender.Text = string.upper(player.Name)
newMessage.Sender.TextColor3 = player.TeamColor.Color
newMessage.Content.Text = message
newMessage.Visible = false
print(player.Team.Name)
print(v.Team.Name)
if v.Team.Name == "Irish Raider" or v.Team.Name == "Civilian" then
if player.Team.Name == "Irish Raider" or player.Team.Name == "Civilian" then
newMessage.Visible = true
print("Sent and received by civs")
else
newMessage.Visible = false
end
else
newMessage.Visible = false
end
if v.Team.Name ~= "Irish Raider" or v.Team.Name ~= "Civilian" then
if player.Team.Name ~= "Irish Raider" or player.Team.Name ~= "Civilian" then
newMessage.Visible = true
print("Sent and received by military")
else
newMessage.Visible = false
end
else
newMessage.Visible = false
end
end
elseif messageType == "Team" then
for i, v in pairs(game.Players:GetChildren()) do
if v.Team == player.Team then
local newMessage = game.ReplicatedStorage.RadioAssets.MessageTemplate:Clone()
newMessage.Parent = v.PlayerGui.Radio.Team.Messages
newMessage.Sender.Text = string.upper(player.Name)
newMessage.Sender.TextColor3 = player.TeamColor.Color
newMessage.Content.Text = message
end
end
end
end)
Hmm not sure. Do you have a Discord or anything else we could speak on? I could try to replicate what you’re doing in my own game with my own custom UI and try to figure out the issue, hard for me to find the issue personally just from reading the code.