How to make player chat something by touching trigger?

I am trying to achieve trigger to force player chat something, how do I do this?

1 Like

To make a Bubble over the head of the player, use Chat:Chat() and if you want it with in chat message too, I guess you could send a message with the player username and making it look real using

game.StarterGui:SetCore( "ChatMakeSystemMessage",  { Text = "["..plr.Name.."]: Hello World", Color = Color3.fromRGB( 255,255,255 ), Font = Enum.Font.Arial, FontSize = Enum.FontSize.Size24 } )

And all of that on a .Touched event, destroying or disabling the trigger to not chat multiple times.

1 Like

Am I doing this right?

Mind giving me the written part of the script, instead of an image? I can’t read it well.

Oh sorry my bad, here it is.

script.Parent.Touched:connect(function(hit)
	local plr = Players.LocalPlayers
	game.StarterGui:SetCore( "ChatMakeSystemMessage",  { Text = "["..plr.Name.."]: Hello friend!", Color = Color3.fromRGB( 255,255,255 ), Font = Enum.Font.Arial, FontSize = Enum.FontSize.Size24 } )	
end)

No. You need to make it client-side and put it in a place the script can run. This is the correct one:

YOUR_PART.Touched:connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not plr then return end
	game.StarterGui:SetCore( "ChatMakeSystemMessage",  {
		Text = "["..plr.Name.."]: Hello friend!",
		Color = Color3.fromRGB( 255,255,255 ),
		Font = Enum.Font.Arial,
		FontSize = Enum.FontSize.Size24 } )
end)

SayMessage exists for this use case. It is the same method used when a client sends a message from the chat bar. It also respects a speaker’s data (e.g. any tags, chat colours, so on) and fires a bubble chat. ChatMakeSystemMessage isn’t really the proper way to do this anymore.

Do take care when forcing a user to chat that they aren’t mentioning anything inappropriate. It’s possible for you to be held accountable for that happening. Just wanted to make that known.

Some rough code I wrote up. This will not work as-is, so you preferably shouldn’t just copy and paste it. Use it as a learning resource to see how I got it done.

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)

Part.Touched:Connect(function (hit)
    -- We want to assume that the hit part is a limb of a character
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if not player then return end

    local speaker = ChatService:GetSpeaker(player.Name)
    if not speaker then return end

    -- Assuming your GeneralChannelName == "All"
    speaker:SayMessage("foobar", "All")
end)

Potential result:

3 Likes