How to Display a Server Chat Message when Part is touched?

Hey there!

I am trying to get a Part to display a specific server text message in the player’s chatbox whenever a specific Part is touched. I know how to display server chat messages using StarterGui but I do not know how to get this function to work or communicate with whenever a Part in Workspace is .Touched.

StarterGui script:

local function ChatMessage(text)
	game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(text)
end
4 Likes

use a local script to detect “.Touched” that fires a remote event, then in a script handle the server message, otherwise only your player will see the message

as for making a message in the chat, you can look into this article

2 Likes

Make server script detecting touch and firing RE.

ServerScriptService:

 Part.Touched:Connect(function()
      TouchRE:FireAllClients()
end

then make local script:
that displays message

StarterPlayerScripts:

TouchRE.OnClientEvent:Connect(function()
	ChatService:WaitForChild("TextChannels"):WaitForChild("RBXSystem"):DisplaySystemMessage("Message There!")
end)
1 Like

Oh, my bad do
local ChatService = game:GetService("TextChatService")


theres and error message:

Players.ahmingiscool.PlayerScripts.Chat System:6: attempt to index nil with ‘Name’

Delate this line it is part of one of my old scripts that was printing player name so the name is there I didn’t see that sorry.

1 Like

Is it possible to turn this into a function where whenever I need to send a server message in a server script, I can use the function in server script to call the local script to send a chat message?

1 Like

Yes, you just need to change the event that fires the function on server.

What exactly do you mean by changing the event? Currently the remote event is fired on the server and received by the local script, which displays whatever message I place in between :DisplaySystemMessage("Message There!").

I would have to change it to :DisplaySystemMessage(text) in LocalScript and have the text as an argument for a function in ServerScript?

You want to display text sent from server?

I want to make it so I can send the text message via a function from a server script. Currently this will only send whatever message I set in the LocalScript.

Just send txt via RE

Part.Touched:Connect(function()
    local text = ""
    TouchRE:FireAllClients(text)
end
1 Like

Ah…I thought it was more complicated than that. Did one previously for GUIs and it was definitely tedious. Will give this a try and let you know if there are any problems. Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.