TextChatService มีคำสั่งแชทที่ติดตั้งไว้สำหรับวัตถุประสงค์ทั่วไป เช่น การปิดเสียงผู้เล่นคนอื่นและการใช้อีโมทของอวาตาร์คุณสามารถเปิดใช้งานได้โดยการตั้งค่า CreateDefaultCommands เป็น true ในหน้าต่างคุณสมบัติของ Studio **** คุณยังสามารถเพิ่มคำสั่งที่กําหนดเองโดยใช้ TextChatCommand ได้ผู้ใช้ส่งคำสั่งที่กำหนดไว้ในแถบการใส่ข้อความแชทกระตุ้นการเรียกกลับที่กำหนดโดย TextChatCommand.Triggered เพื่อดําเนินการด้วยการกำหนดเองแบบกำหนดเองของคุณ
ตัวอย่างต่อไปนี้แสดงวิธีการสร้างคำสั่งแชทที่ช่วยให้ผู้เล่นเพิ่มหรือลดขนาดตัวละครของพวกเขาเมื่อพวกเขาป้อน /super หรือ /mini
เพิ่มตัวอย่าง TextChatCommand ภายใน TextChatService
เปลี่ยนชื่อเป็น SizeCommand
ตั้งค่าคุณสมบัติ PrimaryAlias ของมันเป็น /super และ SecondaryAlias ของมันเป็น /mini
ใส่สิ่งต่อไปนี้ Script ภายใน ServerScriptService เพื่อกำหนดการโทรกลับสำหรับคำสั่งแชทที่ขยายขนาดตัวละคร:
สคริปต์local TextChatService = game:GetService("TextChatService")local Players = game:GetService("Players")local sizeCommand: TextChatCommand = TextChatService:WaitForChild("SizeCommand")sizeCommand.Triggered:Connect(function(textSource, message)local scaleMult = 1local messageWords = string.split(message, " ")if messageWords[1] == "/super" thenscaleMult = 2elseif messageWords[1] == "/mini" thenscaleMult = 0.5endlocal player = Players:GetPlayerByUserId(textSource.UserId)if player thenlocal character = player.Characterif character thenlocal humanoid = character:FindFirstChildWhichIsA("Humanoid")if humanoid thenfor _, child in humanoid:GetChildren() doif child:IsA("NumberValue") thenchild.Value *= scaleMultendendendendendend)