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)
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(message, recipient)
if message:lower() == "!host" then
print("Player ran !host")
end
end)
end)
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)
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
-- 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)