Make an intercom

hello !
I’m currently scripting an intercom which is suppose o take the player sentence in the chat and make the server says it, so here is the script :

local zone = game.Workspace.Detection
function ListenForChat(Player)
	Player.Chatted:Connect(function(Message)
		local Filtered = game:GetService("TextService"):FilterStringAsync(Message, Player.UserId)
		local function chat(message)
			game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = message, Colour = Color3.fromRGB(16, 110, 139), Font = Enum.Font.SourceSans})
		end
		chat(Filtered)
	end)
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if zone.Touched then
			ListenForChat()
		end
	end)
end)
2 Likes

But the problem is that it doesn’t work, but everything looks fine

It seems like you are using 2 chatted events

game.Players.PlayerAdded:Connect(ListenForChat)

Replace the bottom part of your script with this

1 Like

1 Your using the player.ChattedEvent twice and 2 your not passing the parameter player through the ListenForChat() function

Are you calling ChatMakeSystemMsg on the server, if you are, then make a remote event, fire it on clients with the message as the parameter, then make the system msg on the client.

I’m beginner, Idk how to make these kind of event (sorry I’m not very smart)

You can’t use Part.Touched to see if a person is in a zone,
I’m a bit exhausted right now, so I can’t explain Region3’s Right now

Nah I mean fireserver
– Sueless stuff –

local Zone = workspace:WaitForChild("Detection")
function PartToRegion3(part)
	local abs = math.abs

	local cf = obj.CFrame -- this causes a LuaBridge invocation + heap allocation to create CFrame object - expensive! - but no way around it. we need the cframe
	local size = obj.Size -- this causes a LuaBridge invocation + heap allocation to create Vector3 object - expensive! - but no way around it
	local sx, sy, sz = size.X, size.Y, size.Z -- this causes 3 Lua->C++ invocations

	local x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = cf:components() -- this causes 1 Lua->C++ invocations and gets all components of cframe in one go, with no allocations

	-- https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/
	local wsx = 0.5 * (abs(R00) * sx + abs(R01) * sy + abs(R02) * sz) -- this requires 3 Lua->C++ invocations to call abs, but no hash lookups since we cached abs value above; otherwise this is just a bunch of local ops
	local wsy = 0.5 * (abs(R10) * sx + abs(R11) * sy + abs(R12) * sz) -- same
	local wsz = 0.5 * (abs(R20) * sx + abs(R21) * sy + abs(R22) * sz) -- same
	
	-- just a bunch of local ops
	local minx = x - wsx
	local miny = y - wsy
	local minz = z - wsz

	local maxx = x + wsx
	local maxy = y + wsy
	local maxz = z + wsz
   
	local minv, maxv = Vector3.new(minx, miny, minz), Vector3.new(maxx, maxy, maxz)
	return Region3.new(minv, maxv)
end

local Zone3 = PartToRegion3(Zone)

function ListenForChat(plr)
	plr.Chatted:Connect(function(Message)
		local Filtered = game:GetService("TextService"):FilterStringAsync(Message, plr.UserId)
		local function chat(message)
                       if workspace:FindPartInRegion3(Zone3, plr.Character.HumanoidRootPart) then
                              game.ReplicatedStorage.YourRemote:FireAllClients(Filtered)
                       end
		end
		chat(Filtered)
	end)
end

game.Players.PlayerAdded:Connect(chat)

localscript:

ChatRemote.OnClientEvent:Connect(function(message)
			game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = message, Colour = Color3.fromRGB(16, 110, 139), Font = Enum.Font.SourceSans})
end

I copied that region3 function from another post

Try this:

local MessageTime = 10

local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local Debris = game:GetService("Debris")

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local intercom = Instance.new("Message")
		intercom.Text = Chat:FilterStringForBroadcast(msg,player)
		intercom.Parent = workspace
		Debris:AddItem(intercom,MessageTime)
	end)
end)

This will display the filtered message to everyone in the server for the MessageTime amount of seconds.

I was just typing a CoreGui code without using deprecated hints, but ooookay (finished it lol)

Yes, except that for a beginner the depreciated message instance still works and is the fastest way to create a GUI that displays a message everyone can see without having to create a GUI, clone it, edit the specific text label that’s located somewhere in it, and then parent it inside a player’s PlayerGui.

It may be lazy but it accomplishes what he wants.

It looks ugly though
But good point

Is it working for everyone?

By the way some stuff aren’t defined

There are undefined things too

You’re supposed to fill those in with your own remote event in replicated storage
Ok maybe this is too complicated for a beginner

Hmmmmm it’s working but can it works with the chat?
If I say “Hello world” the server say “Hello world” too

No idea what you’re asking. Also, I forgot to mention, if your using this for an intercom system that many people will see then you’ll want to use the FilterStringForBroadcast instead of TextService.

Also, the code I provided will display the message to everyone regardless of who speaks. I recommend you learn more about scripting and all the instances you can use before attempting this.

Ok like :
I’m an random player and I want to say something, I go to the intercom and say : “Hello guys I’m ricardo”
The script take what the player said, and, because I used a proximity chat, will say it to everyone. That’s what I’m trying to do

Alright, I remember a free model that I used way back that actually accomplished what you want. Hold on while I find it.