I need help with Chat Triggers

Hello, I never learned how to do chat triggers. I need help scripting a chat trigger.

basically what I am wanting to do is when you say !host in chat a billboard gui pops up with text saying “Session Host” overhead.

I will reply to everyone.

Thanks for help.

Signed,
J_osq

1 Like

You can use Players.PlayerAdded and then connect a Player.Chatted event to the Player you got from PlayerAdded, and then check the Message argument of Chatted. Something like this:

local Players = game:GetService'Players'

local function OnChatted(Player, Message)
	local Args = string.split(Message, " ") -- Split the message into a table of all words (Useful if you want multi argument commands like ":kick bob Hacking")
	local Command = table.remove(Args, 1) -- Get the first word of the message and remove it from the words table
	if Command == "!host" then
		print'Host'
	end
end

local function OnPlayerAdded(Player)
	if IsAdmin(Player) then -- You have to have some way of checking who is authorized to use the commands
		Player.Chatted:Connect(function(Message)
			OnChatted(Player, Message)
		end)
	end
end

Players.PlayedAdded:Connect(OnPlayerAdded)
1 Like

You can use Player.Chatted event:

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(message, recipient)
		if message:lower() == "!host" then
			print("Player ran !host")
		end
	end)
end)
2 Likes
game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message == "sometimes writing code helps people other than just telling them to do it ~ I program for fun" then
			print(":)")
		end
	end)
end)
2 Likes

Where would I put this script? And how would I get the text to pop up?

1 Like

Youd put it in a server script, in like serverscriptservice

this one
image

1 Like

I put this code in a script in ServerScriptService and once I print “!host” in chat nothing happens.

1 Like

For the text to pop up you would wanna clone a billboard gui from somewhere and parent it in the head of the player who said !host

1 Like

I am very new at this so I really don’t know how I would do tbat so sorry.

1 Like

Make a billboard gui and then put it in ServerStorage and then do this

local HostGui = game:GetService'ServerStorage'.HostGui:Clone() -- assuming the billboard gui is named "HostGui"
HostGui.Parent = Player.Character.Head
HostGui.Adornee = Player.Character.Head
1 Like

This is what I got at the moment

1 Like
-- UserIds of players who have access to chat commands
local Admins = {
	112896842,
	155350575
}

local Players = game:GetService'Players'

local function IsAdmin(Player)
	return table.find(Admins, Player.UserId)
end

local function OnChatted(Player, Message)
	if not IsAdmin(Player) then return end
	local Args = string.split(Message, " ") -- Split the message into a table of all words
	local Command = table.remove(Args, 1) -- Get the first word of the message and remove it from the words table
	if Command == "!host" then
		print'Host'
		local HostGui = game:GetService'ServerStorage'.HostGui:Clone() -- assuming the billboard gui is named "HostGui"
		HostGui.Parent = Player.Character.Head
		HostGui.Adornee = Player.Character.Head
	end
end

local function OnPlayerAdded(Player)
	Player.Chatted:Connect(function(Message)
		OnChatted(Player, Message)
	end)
end

Players.PlayerAdded:Connect(OnPlayerAdded)
2 Likes

Is this in the right order?

image

1 Like

Put the script in a server script inside ServerScriptService

1 Like

Alright done what is the next step?

1 Like

Chat “!host” and it should put the host gui inside of your character

1 Like

Seems not to be working.

1 Like

You need to put a textlabel inside of the billboard gui Lol, and then change the Text property of it to like “Host” or something

1 Like

Oh yeah I am so sorry lol let me do that real quick lol.

1 Like

You can use Player.Chatted but i prefer ChatService because you can do alot of things with it that you can’t do with Player.Chatted.

1 Like