📌
【Roblox開発】プレイヤーがチャットしたイベントとその内容を受け取りカスタムなコマンドをスクリプトで作る方法
はじめに
今回はカスタムなコマンドを作成する方法を共有します。

公式Reference
実装

local Players = game:GetService("Players")
local firstCommand = "/first"
local secondCommand = "/second"
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, _recipient)
if message:sub(1, firstCommand:len()):lower() == firstCommand then
print("FirstCommand !!")
elseif message:sub(1, secondCommand:len()):lower() == secondCommand then
print("SecondCommand !!")
end
end)
end)
PlayerAddedでプレイヤーが入室したタイミングでPlayerのもつChattedイベントの購読を開始します。
Chattedイベントでプレイヤーが発するチャットの内容が受け取ることができるようになっているようです。
引数にあるmessageからどのようなチャットメッセージか判別して指定のコマンドと同じ文字列だたら指定のことを実行するような実装になっています。
実行
Discussion