I am trying to make it where any person on a list of various teams can type something in chat, and a chat bubble will pop up above a part, sort of like a radio system.
Whenever I talk in chat without a remote event, it works but only on my side so not everyone can see the chat bubble
I’ve tried firing a remote event from a player.Chatted but it wouldn’t work, Could someone help me revise my script to make it appear on all player’s screen?
Script
local radioEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“RadioEvent”)
local LETeams = {
[“FBI”] = “”;
}
radioEvent.OnServerEvent:Connect(function(plr,msg)
if LETeams[plr.Team.Name] then
game:GetService(“Chat”):Chat(script.Parent,msg)
end
end)
Local Script
local radioEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“RadioEvent”)
local radioEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“RadioEvent”)
local LETeams = {"FBI"}
radioEvent.OnServerEvent:Connect(function(plr,msg)
if LETeams[plr.Team.Name] then
game:GetService(“Chat”):Chat(script.Parent,msg)
end
end)
local radioEvent = game:GetService("ReplicatedStorage"):WaitForChild("RadioEvent")
local LETeams = {"FBI"}
radioEvent.OnServerEvent:Connect(function(plr,msg)
if LETeams[plr.Team.Name] then
game:GetService("Chat"):Chat(script.Parent,msg)
end
end)
LocalScript
local radioEvent = game:GetService(“ReplicatedStorage”):WaitForChild(“RadioEvent”)
game.Players.ChildAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
radioEvent:FireServer(msg)
end)
end)
Why not handle this purely from the server-side? Is there any specific reason you require the client to be firing off the event?
This is a purely server-sided script that should be placed in ServerScriptService. If you require it to work with multiple entities, simply change it so it posts a bubble to all related adornee bricks.
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local LE_TEAMS = {"FBI"}
-- Use PlayerAdded, not ChildAdded
Players.PlayerAdded:Connect(function (player)
player.Chatted:Connect(function (message)
if player.Team and table.find(LE_TEAMS, player.Team.Name) then
-- Change the first bit to whatever you want
Chat:Chat(workspace.RadioPart, message, Enum.ChatColor.White)
end
end)
end)
The ways you’re suggesting are fundamentally flawed by changing the LETeams table into an array from a dictionary. Your code has not been updated to work in terms of arrays, so a lookup at the index of FBI will be nil.
I would’ve hoped that filtering the message would be an obvious implication as chatting is player-based input, but including the tidbit as an addendum probably would’ve been appropriate. Yes, definitely filter the message as Chatted passes the raw message.
Whenever I try to filter the text it just comes up as “Instance” in the chatbox.
Script
local Players = game:GetService(“Players”)
local Chat = game:GetService(“Chat”)
local TextService = game:GetService(“TextService”)
local LE_TEAMS = {“FBI”}
Players.PlayerAdded:Connect(function (player)
player.Chatted:Connect(function (message)
if player.Team and table.find(LE_TEAMS, player.Team.Name) then
local TextFilterResult = TextService:FilterStringAsync(message, player.UserId)
Chat:Chat(workspace.lol.Misc.SW.RadioPart, TextFilterResult, Enum.ChatColor.White)
end
end)
end)
This is because you’re passing TextFilterResult as the chat message. TextFilterResult is an object and the Chat method is calling tostring on it, which just returns the name of the object. Read further into the article to understand how to fully use TextService, or see TextFilterResult’s documentation page.
You will need to call one of the methods from TextFilterResult and pass that instead of the TextFilterResult. For this kind of use, you’re probably going to want to look at GetNonChatStringForBroadcastAsync.