คำสั่งแชทข้อความที่กำหนดเอง

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

TextChatService มีคำสั่งแชทในตัวสำหรับวัตถุประสงค์ทั่วไป เช่น การปิดเสียงผู้เล่นคนอื่นและการใช้อีโมจิของอวตาร คุณสามารถเปิดใช้งานได้โดยการตั้งค่า CreateDefaultCommands เป็น true ในหน้าต่าง คุณสมบัติ ของ Studio

คุณยังสามารถเพิ่มคำสั่งที่กำหนดเองโดยใช้ TextChatCommand ผู้ใช้ที่ส่งคำสั่งที่กำหนดในแถบการป้อนข้อความจะกระตุ้นการเรียกกลับที่กำหนดโดย TextChatCommand.Triggered เพื่อดำเนินการที่ปรับแต่งตามที่คุณต้องการ

ตัวอย่างต่อไปนี้แสดงวิธีการสร้างคำสั่งแชทที่อนุญาตให้ผู้เล่นสามารถเพิ่มหรือลดขนาดตัวละครเมื่อพวกเขาป้อน /super หรือ /mini

  1. เพิ่มอินสแตนซ์ TextChatCommand ภายใน TextChatService

  2. เปลี่ยนชื่อเป็น SizeCommand.

  3. ตั้งค่าคุณสมบัติ PrimaryAlias เป็น /super และ SecondaryAlias เป็น /mini.

  4. แทรก Script ต่อไปนี้ภายใน ServerScriptService เพื่อตั้งค่าการเรียกกลับสำหรับคำสั่งแชทที่ปรับขนาดตัวละคร:

    Script

    local TextChatService = game:GetService("TextChatService")
    local Players = game:GetService("Players")
    local sizeCommand: TextChatCommand = TextChatService:WaitForChild("SizeCommand")
    sizeCommand.Triggered:Connect(function(textSource, message)
    local scaleMult = 1
    local messageWords = string.split(message, " ")
    if messageWords[1] == "/super" then
    scaleMult = 2
    elseif messageWords[1] == "/mini" then
    scaleMult = 0.5
    end
    local player = Players:GetPlayerByUserId(textSource.UserId)
    if player then
    local character = player.Character
    if character then
    local humanoid = character:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
    for _, child in humanoid:GetChildren() do
    if child:IsA("NumberValue") then
    child.Value *= scaleMult
    end
    end
    end
    end
    end
    end)
©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ