Players

แสดงที่เลิกใช้งานแล้ว

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

ไม่สามารถสร้าง
บริการ

บริการ Players มี Player วัตถุสำหรับลูกค้าที่เชื่อมต่ออยู่ในขณะนี้กับเซิร์ฟเวอร์ Roblox มันยังมีข้อมูลเกี่ยวกับการตั้งค่าของสถานที่ เช่น การปรากฏตัวขอ

สรุป

คุณสมบัติ

  • ไม่ซ้ำ
    ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน

    เปิดหรือปิดวิธีการ Players สาม ( BanAsync() , UnbanAsync() และ 2>Class.Players:GetBanHistoryAsync()|GetBanHistoryAsync()2> ) ซึ่งเป็น API

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ระบุว่ามีการแชทฟองหรือไม่ มันกำหนดด้วยวิธี Players:SetChatStyle()

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ระบุว่า Class.Character|Characters จะเกิดใหม่อัตโนมัติ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ระบุว่าคุณสนุกกับการแชทคลาสสิกหรือไม่; ตั้งค่าโดยวิธี Players:SetChatStyle()

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Class.Player ที่ LocalScript กำลังประมวลผลสำหรับ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    จำนวนผู้เล่นสูงสุดที่สามารถอยู่ในเซิร์ฟเวอร์

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    จำนวนผู้เล่นที่ต้องการสำหรับเซิร์ฟเวอร์

  • อ่านพร้อมๆ กัน

    ควบคุมเวลาที่ใช้สำหรับตัวละครของผู้เล่นที่จะเกิดใหม่

  • ไม่สามารถเขียนสคริปต์
    อ่านพร้อมๆ กัน

วิธีการ

  • Chat(message : string):()
    การรักษาความปลอดภัยของปลั๊กอิน

    ทำให้ผู้เล่นในเกมพูดสิ่งที่ได้รับการแสดงผล

  • เขียนพร้อมๆ กัน

    กลับ Player ด้วย UserId หากพวกเขาอยู่ในเกม

  • กลับสู่ Player ซึ่งมี Character อินสแตนซ์หรือ nil ถ้าหนึ่งไม่สามารถพบได้

  • GetPlayers():Instances
    เขียนพร้อมๆ กัน

    กลับตารางของ all ปัจจุบัน Player วัตถุ

  • การรักษาความปลอดภัยของปลั๊กอิน

    ตั้งค่าว่า BubbleChat และ ClassicChat ใช้งานอยู่หรือไม่ และบอก TeamChat และ Class.แชท ว่าจะทำอย่างไร

  • TeamChat(message : string):()
    การรักษาความปลอดภัยของปลั๊กอิน

    ทำให้ LocalPlayer แชทข้อความที่ให้ไว้ซึ่งจะมองเห็นได้เฉพาะผู้ใช้ในทีมเดียวกันเท่านั้น

  • BanAsync(config : Dictionary):()
    ผลตอบแทน

    แบนผู้ใช้จากประสบการณ์ของคุณด้วยตัวเลือกในการระบุระยะเวลารายการเหตุผลว่าบันทึกจะใช้กับจักรวาลทั้งหมดหรือเฉพาะสถานที่ปัจจุบันหรือไม่ และอื่น ๆ อีกมากมาย วิธีนี้เปิ

  • ผลตอบแทน

    กลับตัวละคร Model ที่พร้อมด้วยสิ่งที่ระบุไว้ในคำอธิบายของมนุษย์ และเป็น R6 หรือ R15 ตามที่ระบุโดยรุ่น

  • ผลตอบแทน

    กลับชุดตัวละครที่กำหนดไว้พร้อมกับทุกอย่างที่ติดตั้งเพื่อจับคู่กับ avatar ของผู้ใช้ที่ระบุโดยผู้ใช้ที่ผ่านใน UserID

  • ผลตอบแทน

    ดึงประวัติการแบนและการเลิกแบนของผู้ใช้ในจักรวาลของประสบการณ์ วิธีนี้เปิดใช้งานและปิดใช้งานโดย Players.BanningEnabled โปรไฟล์ที่คุณสามารถเปิดใช้ใน Studio

  • ผลตอบแทน

    กลับข้อมูลเกี่ยวกับลักษณะของตัวละครของผู้ใช้ที่ให้

  • ผลตอบแทน

    กลับมาเป็นวัตถุ FriendPages ที่มีข้อมูลสำหรับเพื่อนของผู้เล่นทั้งหมด

  • กลับค่า HumanoidDescription สำหรับชุดที่กำหนดซึ่งจะถูกตั้งค่าด้วยส่วน/สี/อนิเมชั่นต่างๆ ของชุด

  • กลับมาเป็นค่า HumanoidDescription ซึ่งระบุสิ่งที่ติดตั้งสำหรับอวตารของผู้ใช้ที่ระบุโดยผู้ใช้ที่ผ่านใน UserID

  • ผลตอบแทน

    ส่งคำถามไปยังเว็บไซต์ Roblox สำหรับชื่อผู้ใช้บัญชีที่มี UserId ที่กำหนด

  • ผลตอบแทน

    ส่งคำถามไปยังเว็บไซต์ Roblox สำหรับ userId ของบัญชีที่มีชื่อผู้ใช้ที่กำหนด

  • GetUserThumbnailAsync(userId : number,thumbnailType : Enum.ThumbnailType,thumbnailSize : Enum.ThumbnailSize):Tuple
    ผลตอบแทน

    ส่ง URL เนื้อหาของรูปประกายผู้เล่นที่มีขนาดและประเภทเช่นเดียวกับตัวเลือกที่เป็นบูลีนที่ระบุว่ารูปภาพพร้อมให้ใช้งานหรือไม่

  • UnbanAsync(config : Dictionary):()
    ผลตอบแทน

    ยกเลิกการแบนผู้เล่นที่ถูกแบนจาก Players:BanAsync() หรือ User Restrictions Open Cloud API เมื่อใดก็ได้ วิธีนี้เปิดใช้งานและปิดใช้งานโดย Players.BanningEnabled ระเบียนที่คุณสามารถเปิด/ปิดใน Studio

อีเวนต์

  • เกิดขึ้นเมื่อผู้เล่นเข้าสู่เกม

  • เกิดขึ้นเมื่อเซิร์ฟเวอร์เกมระзнаนั้นว่าสมาชิกของผู้เล่นเปลี่ยนแปลง

  • จะเกิดขึ้นเมื่อผู้เล่นกำลังจะออกจากเกม

  • เกิดขึ้นเมื่อเซิร์ฟเวอร์เกมระзнаนี้ว่าสถานะของผู้ใช้สำหรับการสมัครใหม่นั้นเปลี่ยนแปลงไป

คุณสมบัติ

BanningEnabled

ไม่ซ้ำ
ไม่สามารถเขียนสคริปต์
อ่านพร้อมๆ กัน

เปิดหรือปิดวิธีการ Players สาม ( BanAsync() , UnbanAsync() และ 2>Class.Players:GetBanHistoryAsync()|GetBanHistoryAsync()2> ) ซึ่งเป็น API

BubbleChat

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

ลักษณะ BubbleChat ระบุว่ามีการเปิดใช้งานการแชทฟองหรือไม่ มันกำหนดด้วยวิธี Players:SetChatStyle() โดยใช้ Enum.ChatStyle รายการ

เมื่อโหมดแชทนี้เปิดใช้งาน, เกมจะแสดงการแชทใน UI ของผู้ใช้ในมุมด้านบนซ้ายของหน้าจอ

มีโหมดแชทอื่น ๆ สองโหมดคือ Players.ClassicChat และโหมดแชทที่เปิดใช้งานทั้งแชทคลาสสิกและแชทฟอง

CharacterAutoLoads

ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัติ CharacterAutoLoads ระบุว่า Class.Character|Characters จะเกิดใหม่อัตโนมัติหรือไม่ ค่าเริ่มต้นคือ true

หากคุณสมบัตินี้ถูกปิดใช้งาน (ไม่ใช่) ผู้เล่น Class.Character|Characters จะไม่เกิดจนกว่าฟังก์ชัน Player:LoadCharacter() จะถูกเรียกสำหรับผู้เล่นแต่ละรายรวมทั้งเมื่อผู้เล่นเข้าร่วมประสบก

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

ตัวอย่างโค้ด

This example demonstrates one possible usage of the Players.CharacterAutoLoads property.

The example below respawns all players in the game, if dead, once every 10 seconds. This means that players who die 1 second after all players respawn must wait 9 seconds until the script loads all Player.Character again.

First, this script removes a player's character when they die and the Humanoid.Died function fires. This is done so that the respawn loop that executes every 10 seconds reloads that player when it does not find the player's character in the Workspace.

To work as expected, this example should be run within a Script.

Player Respawn Timer

local Players = game:GetService("Players")
-- Set CharacterAutoLoads to false
Players.CharacterAutoLoads = false
-- Remove player's character from workspace on death
Players.PlayerAdded:Connect(function(player)
while true do
local char = player.CharacterAdded:Wait()
char.Humanoid.Died:Connect(function()
char:Destroy()
end)
end
end)
-- Respawn all dead players once every 10 seconds
while true do
local players = Players:GetChildren()
-- Check if each player is dead by checking if they have no character, if dead load that player's character
for _, player in pairs(players) do
if not workspace:FindFirstChild(player.Name) then
player:LoadCharacter()
end
end
-- Wait 10 seconds until next respawn check
task.wait(10)
end

ClassicChat

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

ระบุว่ามีการเปิดใช้งานหรือไม่ใช้งานการแชทคลาสสิกหรือไม่ สิ่งนี้กำหนดโดยวิธี Players:SetChatStyle() โดยใช้สมบุก Enum.ChatStyle สมบุก

เมื่อเปิดใช้งานโหมดแชทนี้ เกมจะแสดงการแชทในฟองอากาศเหนือหัวของผู้ส่ง

มีโหมดแชทอื่น ๆ สองโหมดคือ Players.BubbleChat และโหมดแชทที่เปิดใช้งานทั้งคลาสสิกและบับเบิลชาท

LocalPlayer

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

LocalPlayer เป็นสมบัติที่อ่านเท่านั้นซึ่งระบุว่า Player ของลูกค้าที่กำลังรันเว็บไซต์

คุณสมบัตินี้จะถูกกำหนดเฉพาะสำหรับ LocalScripts และ ModuleScripts ตามที่ต้องการโดยพวกเขาเนื่องจากพวกเขาทำงานบนเครื่องคอมพิวเตอร์ สำหร

MaxPlayers

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

คุณสมบัติ MaxPlayers กำหนดจำนวนผู้เล่นสูงสุดที่สามารถอยู่ในเซิร์ฟเวอร์ได้ คุณสมบัตินี้สามารถกำหนดได้ผ่านการตั้งค่าสถานที่ที่เฉพาะเจาะจงใน ครีเอตอร์ดาชาร์ด หรือผ

PreferredPlayers

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

คุณสมบัติ PreferredPlayers Robloxจำนวนนี้จะน้อยกว่าจำนวนผู้เล่นสูงสุด ( Players.MaxPlayers ) ที่รองรับโดยประสบการณ์

RespawnTime

อ่านพร้อมๆ กัน

สมบัติ RespawnTime ควบคุมเวลาในวินาทีที่ผู้เล่นต้องใช้เวลาในการเกิดใหม่เมื่อ Players.CharacterAutoLoads เป็นจริง มันเริ่มต้นที่ 5.0 วินาที

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

แม้ว่าคุณสมบัตินี้สามารถตั้งค่าได้จากภายใน Script คุณสามารถตั้งค่าได้ง่ายขึ้นโดยตรงที่ Players วัตถุในหน้าต่าง Explorer ของ Studio

UseStrafingAnimations

ไม่สามารถเขียนสคริปต์
อ่านพร้อมๆ กัน

วิธีการ

Chat

()
การรักษาความปลอดภัยของปลั๊กอิน

ระบบนี้ทำให้ผู้เล่นในเกมพูดคุยข้อความที่กำหนด เนื่องจากรายการนี้ได้รับการป้องกันจึงจะเกิดข้อผิดพลาดหากพยายามใช้ใน Script หรือ LocalScript

แทนที่นั้นเมื่อสร้างระบบการแชทที่กําหนดเองหรือระบบที่ต้องการการเข้าถึงแชทคุณสามารถใช้ฟังก์ชัน Chat ของบริการ Chat:Chat() แทน

พารามิเตอร์

message: string

ข้อความแชท


ส่งค่ากลับ

()

ตัวอย่างโค้ด

This example demonstrates that the Players:Chat() function executes without error if using the Command Bar or a Plugin (assuming the local player can chat freely) and errors if executed in a Script.

Players:Chat

-- Command bar
game:GetService("Players"):Chat("Hello, world!") --Results in 'Hello, world!' appearing in the Chat log under your Player's name.
-- Script
local Players = game:GetService("Players")
Players:Chat("Hello, world!") --Errors

GetPlayerByUserId

เขียนพร้อมๆ กัน

ฟังก์ชันนี้ค้นหาแต่ละ player ใน Players สำหรับผู้ที่มี Player.UserId ตรงกับ UserId ที่ให้ หากผู้เล่นดังกล่าวไม่มีอยู่จริง, มันจะเพียงแค่


local Players = game:GetService("Players")
local function getPlayerByUserId(userId)
for _, player in Players:GetPlayers() do
if player.UserId == userId then
return player
end
end
end

วิธีนี้มีประโยชน์ในการค้นหาผู้ซื้อผลิตภัณฑ์ของผู้พัฒนาโดยใช้ MarketplaceService.ProcessReceipt ซึ่งให้ตารางที่รวม UserId ของผู้ซื้อและไม่ใช่การอ้างอิงไปยังตัวแทน Player เอง ส่วนใหญ่

พารามิเตอร์

userId: number

Class.Player.UserId ของผู้เล่นที่กำหนด


ส่งค่ากลับ

ตัวอย่างโค้ด

Players:GetPlayerByUserId

local Players = game:GetService("Players")
local player = Players:GetPlayerByUserId(1)
if player then
print("Player with userId 1 is in this server! Their name is: " .. player.Name)
else
print("Player with userId 1 is not in this server!")
end

The following code sample:

  • Sets up the ProcessReceipt callback function to handle the purchase of two developer products for an experience.
  • Checks for and records purchases using a GlobalDataStore called PurchaseHistory.
  • Properly returns PurchaseGranted if the transaction completes successfully, or if the function detects that the purchase has already been granted using the PurchaseHistory data store.
ProcessReceipt Callback

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
-- Data store setup for tracking purchases that were successfully processed
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
-- ProductId 123123 for a full heal
productFunctions[123123] = function(_receipt, player)
-- Logic for the player buying a full heal
if player.Character and player.Character:FindFirstChild("Humanoid") then
-- Heal the player to full health
player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
-- Indicate a successful purchase
return true
end
end
-- ProductId 456456 for 100 gold
productFunctions[456456] = function(_receipt, player)
-- Logic for player buying 100 gold
local stats = player:FindFirstChild("leaderstats")
local gold = stats and stats:FindFirstChild("Gold")
if gold then
gold.Value = gold.Value + 100
-- Indicate a successful purchase
return true
end
end
-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)
-- Check the data store to determine if the product was already granted
local playerProductKey = receiptInfo.PurchaseId
local purchased = false
local success, result, errorMessage
success, errorMessage = pcall(function()
purchased = purchaseHistoryStore:GetAsync(playerProductKey)
end)
-- If the purchase is recorded, the product was already granted
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
error("Data store error:" .. errorMessage)
end
-- Update the purchase record
local success, isPurchaseRecorded = pcall(function()
return purchaseHistoryStore:UpdateAsync(playerProductKey, function(alreadyPurchased)
if alreadyPurchased then
return true
end
-- Find the player who made the purchase in the server
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- The player probably left the game
-- If the player returns, the callback is called again
return nil
end
local handler = productFunctions[receiptInfo.ProductId]
local success, result = pcall(handler, receiptInfo, player)
-- Do not record the purchase if granting the product failed
if not success or not result then
error("Failed to process a product purchase for ProductId: " .. tostring(receiptInfo.ProductId) .. " Player: " .. tostring(player) .. " Error: " .. tostring(result))
return nil
end
-- Record the transaction in purchaseHistoryStore
return true
end)
end)
if not success then
error("Failed to process receipt due to data store error.")
return Enum.ProductPurchaseDecision.NotProcessedYet
elseif isPurchaseRecorded == nil then
-- Did not update the value in the data store
return Enum.ProductPurchaseDecision.NotProcessedYet
else
-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt

GetPlayerFromCharacter

ฟังก์ชันนี้กลับค่า Player ที่เกี่ยวข้องกับ Player.Character หรือ nil หากไม่สามารถพบได้ มันเทียบเท่ากับฟังก์ชันต่อไปนี้:


local function getPlayerFromCharacter(character)
for _, player in game:GetService("Players"):GetPlayers() do
if player.Character == character then
return player
end
end
end

วิธีนี้มักใช้เมื่อเหตุการณ์บางอย่างในตัวละครของผู้เล่นเกิดขึ้น (เช่น Class.Humanoid``Class.Humanoid.Died|dying ) เช่นอีเวนต์นี้อาจไม่ได้อ้างอิงไป

พารามิเตอร์

character: Model

ตัวอย่างตัวละครที่คุณต้องการจะได้รับผู้เล่น


ส่งค่ากลับ

ตัวอย่างโค้ด

Players:GetPlayerFromCharacter

Players:GetPlayerFromCharacter

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local PLAYER_NAME = "Nightriff"
local character = Workspace:FindFirstChild(PLAYER_NAME)
local player = Players:GetPlayerFromCharacter(character)
if player then
print(`Player {player.Name} ({player.UserId}) is in the game`)
else
print(`Player {PLAYER_NAME} is not in the game!`)
end

GetPlayers

Instances
เขียนพร้อมๆ กัน

วิธีนี้กลับตารางของทุกวัตถุ Player ที่เชื่อมต่ออยู่ มันทำงานอย่างเดียวกับที่ Instance:GetChildren() จะยกเว้นว่ามันเท่านั


local Players = game:GetService("Players")
for _, player in Players:GetPlayers() do
print(player.Name)
end

สคริปที่เชื่อมต่อกับ Players.PlayerAdded มักจะพยายามที่จะประมวลผลผู้เล่นที่เชื่อมต่อกับเกม วิธีนี้มีประโยชน์สำหรับการซ้ำผู้เล่นที่ไม่ได้เปิดไฟ Class.Players.Player


local Players = game:GetService("Players")
local function onPlayerAdded(player)
print("Player: " .. player.Name)
end
for _, player in Players:GetPlayers() do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)

ส่งค่ากลับ

Instances

ตารางที่มีผู้เล่นทั้งหมดในเซิร์ฟเวอร์

ตัวอย่างโค้ด

This code sample listens for players spawning and gives them Sparkles in their head. It does this by defining two functions, onPlayerSpawned and onPlayerAdded.

Give Sparkles to Everyone

local Players = game:GetService("Players")
local function onCharacterAdded(character)
-- Give them sparkles on their head if they don't have them yet
if not character:FindFirstChild("Sparkles") then
local sparkles = Instance.new("Sparkles")
sparkles.Parent = character:WaitForChild("Head")
end
end
local function onPlayerAdded(player)
-- Check if they already spawned in
if player.Character then
onCharacterAdded(player.Character)
end
-- Listen for the player (re)spawning
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

SetChatStyle

()
การรักษาความปลอดภัยของปลั๊กอิน

คุณสมบัตินี้ตั้งค่าว่า BubbleChat และ ClassicChat ใช้งานอยู่หรือไม่และบอกทีม Chat และ Chat ว่าจะทำอย่างไรโดยใช้ Enum.ChatStyle คอลเลกชัน เนื่องจากรายการนี้ได้รับการป้องกันจึง

หน้าฟังนี้ใช้งานภายในเมื่อโหมดแชทถูกกำหนดโดยเกม

พารามิเตอร์

การตั้งค่ารูปแบบการแชทที่กำหนด

ค่าเริ่มต้น: "Classic"

ส่งค่ากลับ

()

ตัวอย่างโค้ด

This example demonstrates that the Players:SetChatStyle() function executes without error if using the Command Bar or a Plugin and errors if executed in a LocalScript.

When executed in the Command Bar, this code sets the chat style to Classic using the Enum.ChatStyle enum.

Setting a Player's Chat Style

-- Command bar
game.Players:SetChatStyle(Enum.ChatStyle.Classic) -- Set's chat style to Classic
-- LocalScript
local Players = game:GetService("Players")
Players:SetChatStyle(Enum.ChatStyle.Classic) -- Errors

TeamChat

()
การรักษาความปลอดภัยของปลั๊กอิน

ฟังก์ชันนี้ทำให้ Players.LocalPlayer แชทข้อความที่ให้ ซึ่งจะมีเฉพาะผู้ใช้ในทีมเดียวกันเท่านั้น เนื่องจากรายการนี้ได้รับการปกป้องจึงจะทำให้เกิดข้อผิดพลาด

ฟังก์ชันนี้ใช้ภายในเมื่อ Players.LocalPlayer ส่งข้อความถึงทีมของพวกเขา

พารามิเตอร์

message: string

ข้อความกําลังถูกแชท


ส่งค่ากลับ

()

ตัวอย่างโค้ด

This example demonstrates that the Players:TeamChat() function executes without error if using the Command Bar or a Plugin and errors if executed in a LocalScript.

When executed in the Command Bar, the function sends the specified message to all players on the same Team as the Players.LocalPlayer.

Sending Team Chat

-- Command bar
game.Players:TeamChat("Hello World") -- Sends a "Hello World" message to all players on the local player's team
-- LocalScript
local Players = game:GetService("Players")
Players:TeamChat("Hello World") -- Errors

BanAsync

()
ผลตอบแทน

วิธี Players:BanAsync() ช่วยให้คุณสามารถเปิดเผยได้อย่างง่ายดายผู้ใช้ที่ละเมิดกฎของประสบการณ์ของคุณ

การแบนและการส่งข้อความ

Robloxพวกเขาจะได้รับการแสดงผ

สถานที่และจักรวาล

โดยปกติ, แบนจะขยายไปยังสถานที่ใด ๆ ภายในจักรวาลนั้น เพื่อจำกัดแบนให้แคบลงไปยังสถานที่เท่านั้นที่เรียก API นี้, กำหนด ApplyToUniverse เพื

บัญชีอื่น

ผู้ใช้มักจะเล่นภายใต้หลายบัญชีที่แตกต่างกันซึ่งเป็นที่รู้จักกันในนามบัญชีแยกหรือบัญชีอื่น ๆ ซึ่งใช้เพื่อหลบเลี่ยงการแบนบัญชี หาก

ระยะเวลาการแบน

ไม่ใช่ทุกการฝ่าฝืนที่เ

ข้อผิดพลาดและ Throttling

วิธีนี้เรียกใช้การโทรแบบ HTTP ไปยังบริการแบ็คเก็ตที่อยู่ภายใต้การปรับปรุงและอาจล้มเหลว หากคุณเรียกวิธีนี้ด้วยม

HTTP failure for UserId 2: Timedout, HTTP 504 (Service unavailable) failure for UserId 4: Service exception

ข้อความจะรวมถึง failure for UserId {} หากเป็นข้อผิดพลาด HTTP

ความต้องการของฝั่งลูกค้า

เนื่องจากความเสี่ยงที่เกี่ยวข้องกับการแบนผู้ใช้, วิธีนี้อาจจะเรียกในเซิร์ฟเวอร์ระดับต้นฉบับ (การโทรกเข้าจากด้านล่างจะส่งผลในข้อผิดพลาด) คุณสามารถทดสอบ API นี้ใ

API นี้ใช้ ระเบียบาดาลของผู้ใช้เปิด Cloud API คุณจะสามารถใช้ API เหล่านี้เพื่อจัดการการแบนในแอปพลิเคชันของบุคคลที่สาม

พารามิเตอร์

config: Dictionary
  • UserIds (ต้องการ; รายการ) — รายการของ UserIds ของผู้เล่นที่จะถูกแบน ขนาดสูงสุดคือ 50

  • ApplyToUniverse (ไม่บังคับ; ตัวเลือก) — ว่าจะแพร่กระจายไปยังสถานที่ทั้งหมดภายในจักรวาลของประสบการณ์ ปกติคือ true ค่าเริ่มต้นคือ number1 ค่า

  • Duration (ต้องการ; ตัวเลข) — ระยะเวลาของการแบน, ในวินาที. การแบนถาวรควรมีค่าของ -1 . 0 และค่าอื่น ๆ ที่เป็นโมฆะทั้งหมดไม่ถูกต้อง

  • DisplayReason (ต้องการ; สตริง) — ข้อความที่จะแสดงให้กับผู้ใช้เมื่อพวกเขาพยายามและล้มเหลวในการเข้าร่วมประสบการณ์ ความยาวสูงสุดของสตริงคือ 400

  • PrivateReason (ต้องการ; สตริง) — การส่งข้อความภายในที่จะถูกส่งเมื่อขอประวัติการแบนของผู้ใช้ ความยาวสูงสุดของสตริงคือ 1000 .

  • ExcludeAltAccounts (ตัวเลือก; ตัวเลือก) — เมื่อ true ไม่พยายามแบนบัญชี alt ค่าเริ่มต้นคือ false และ Roblox ไม่พยายามแบนบัญชี alt ในขณะที่ค่าเริ่มต้นคือ 0> number10> สำหรับบัญชีที่มี Thai:


ส่งค่ากลับ

()

ตัวอย่างโค้ด

The following example bans a user with a duration calculated from their ban history, scoped to the entire universe and all of the user's alternate accounts.

Banning Users

local Players = game:GetService("Players")
if shouldBeBanned(player) then
local banHistoryPages = Players:GetBanHistoryAsync(player.UserId)
local duration = getNextBanDuration(banHistoryPages) -- Creator-implemented logic
local config: BanConfigType = {
UserIds = {player.UserId},
Duration = duration,
DisplayReason = "You violated community guideline #5",
PrivateReason = "Put anything here that the user should not know but is helpful for your records",
ExcludeAltAccounts = false,
ApplyToUniverse = true
}
local success, err = pcall(function()
return Players:BanAsync(config)
end)
print(success, err)
end

CreateHumanoidModelFromDescription

ผลตอบแทน

กลับตัวละคร Model ที่พร้อมด้วยสิ่งที่ระบุไว้ในคำอธิบายของมนุษย์ และเป็น R6 หรือ R15 ตามที่ระบุโดยรุ่น

พารามิเตอร์

description: HumanoidDescription

ระบุรูปลักษณ์ของตัวละครที่กลับมา

ระบุว่าตัวละครที่กลับมาจะเป็น R6 หรือ R15

assetTypeVerification: Enum.AssetTypeVerification

ประเภทของสินทรัพย์ตรวจสอบว่าระบบนี้จะโหลดแบบจำลองหรือไม่ (คุณควรตั้งค่านี้เป็นเสมอยกเว้นคุณต้องการโหลดสินทรัพย์นอกแคตตาล็อก)

ค่าเริ่มต้น: "Default"

ส่งค่ากลับ

แบบตัวละคร Humanoid

ตัวอย่างโค้ด

This code sample creates a Humanoid Model from the passed in HumanoidDescription and parents the Model to the Workspace.

Create Humanoid Model From Description

game.Players:CreateHumanoidModelFromDescription(Instance.new("HumanoidDescription"), Enum.HumanoidRigType.R15).Parent = game.Workspace

CreateHumanoidModelFromUserId

ผลตอบแทน

กลับชุดตั้งต้นของตัวละครที่มีทุกอย่างพร้อมที่จะตรงกับอวาตาร์ของผู้ใช้ที่ระบุโดยผู้ใช้ที่ผ่านในไอดี. นี่รวมถึงว่าตัวละครนั้นเป็น R6 หรือ R15 ในขณะนี้หรือไม่

พารามิเตอร์

userId: number

รหัสผู้ใช้สำหรับผู้ใช้ Roblox (The UserId คือเลขที่อยู่ในโปรไฟล์ของผู้ใช้เช่น www.roblox.com/users/1/profile)


ส่งค่ากลับ

แบบตัวละคร Humanoid

ตัวอย่างโค้ด

This code sample creates a Humanoid Model to match the avatar of the passed in User ID, and parents the Model to the Workspace.

Create Humanoid Model From A User ID

game.Players:CreateHumanoidModelFromUserId(1).Parent = game.Workspace

GetBanHistoryAsync

ผลตอบแทน

ดึงรายการแบนและยกเลิกแบนของผู้ใช้ในจักรวาลของประสบการณ์ วิธีนี้จะกลับรายการ BanHistoryPages ที่มีมาจาก Pages โดยใช้คุณสมบัติ Players.BanningEnabled

การโทรหาฟังก์ชันนี้จะประสบความสำเร็จเฉพาะในเซิร์ฟเวอร์เกมการผลิตเท่านั้นและไม่ใช่ในอุปกรณ์ลูกค้าหรือใน Studio

API นี้ใช้ ระเบียบาดาลของผู้ใช้เปิด Cloud API คุณจะสามารถใช้ API เหล่านี้เพื่อจัดการการแบนในแอปพลิเคชันของบุคคลที่สาม

พารามิเตอร์

userId: number

ส่งค่ากลับ

ดู BanHistoryPages สำหรับหน้าอ้างอิงการกลับ

GetCharacterAppearanceInfoAsync

ผลตอบแทน

ฟังก์ชันนี้สร้างข้อมูลเกี่ยวกับอวาตาร์ของผู้เล่น (เพิกเฉยเกียร์) ในเว็บไซต์ Roblox ในรูปแบบของพจนานุกรม ไม่ใช่ Class.Players:GetCharacter


<tr>
<td><code>สินทรัพย์</code></td>
<td>ตาราง (ดูด้านล่าง)</td>
<td>อธิบายสินค้าติดตั้ง (หมวก, ส่วนตัวอาจารย์, ฯลฯ)</td>
</tr>
<tr>
<td><code>สีตัวอักษร</code></td>
<td>ตาราง (ดูด้านล่าง)</td>
<td>อธิบายค่า BrickColor สำหรับแต่ละส่วน</td>
</tr>
<tr>
<td><code>สีตัวอักษร3</code></td>
<td>ตาราง (ดูด้านล่าง)</td>
<td>อธิบายตัวอินสแตนซ์สี 3 สำหรับแต่ละส่วนที่อาจไม่ตรงกับสีตัว</td>
</tr>
<tr>
<td><code>กางเกงปกติที่ใช้</code></td>
<td>บูล</td>
<td>อธิบายว่ามีการใช้กางเกงเริ่มต้นหรือไม่</td>
</tr>
<tr>
<td><code>เสื้อเริ่มต้นที่ใช้ได้</code></td>
<td>บูล</td>
<td>อธิบายว่าเสื้อเริ่มต้นจะถูกใช้หรือไม่</td>
</tr>
<tr>
<td><code>อิโมจิ</code></td>
<td>ตาราง (ดูด้านล่าง)</td>
<td>อธิบายอนิเมชัน emote ที่ติดตั้ง</td>
</tr>
<tr>
<td><code>ประเภท playerAvatarType</code></td>
<td>สตริง</td>
<td>R15 หรือ R6</td>
</tr>
<tr>
<td><code>ขนาดเครื่องชั่ง</code></td>
<td>ตาราง (ดูด้านล่าง)</td>
<td>อธิบายปัจจัยการปรับขนาดต่างๆ</td>
</tr>
ชื่อชนิดคำอธิบาย
สมุดอันดับสินทรัพย์

ตาราง assets เป็นรายการของตารางที่ประกอบด้วยสามสิบหกตัวอักษรที่อธิบายสินทรัพย์ที่กำลังสวมใส่โดยผู้เล่น:


<tr>
<td><code>id รหัส</code></td>
<td>จํานวน</td>
<td>รหัสสินทรัพย์ของสินทรัพย์ที่ติดตั้ง</td>
</tr>
<tr>
<td><code>assetType รายการทรัพยากร</code></td>
<td>ตาราง</td>
<td>ตารางที่มีชื่อ และช่อง id แต่ละรายการอธิบายประเภทของสินทรัพย์ที่ติดตั้ง ("Hat", "Face", etc")</td>
</tr>
<tr>
<td><code>ชื่อ</code></td>
<td>สตริง</td>
<td>ชื่อของสินทรัพย์ที่ติดตั้ง</td>
</tr>
ชื่อชนิดคำอธิบาย
ขนาดเครื่องชั่ง

ตาราง scales มีคีย์ต่อไปนี้สำหรับแต่ละ Humanoid คุณสมบัติการขนาดตัวอักษร: bodyType , 1> head1> , 4> height

สีตัวอย่างสี

ตาราง bodyColors มีรหัสสำคัญต่อไปนี้สำหรับเลข BrickColor รหัสที่ตรง

พารามิเตอร์

userId: number

รหัสผู้ใช้ * ของผู้เล่นที่ระบุ


ส่งค่ากลับ

พจนานุกรมที่มีข้อมูลเกี่ยวกับลักษณะของตัวละครของผู้ใช้ที่ให้

ตัวอย่างโค้ด

Sometimes it is best to see an example of the returned dictionary structure in pure Lua. Here is one such example of a player whose avatar uses a package and wears several hats. Can you guess who it is?

Example Return Character Appearance Dictionary

local result = {
playerAvatarType = "R15",
defaultPantsApplied = false,
defaultShirtApplied = false,
scales = {
bodyType = 0,
head = 1,
height = 1.05,
proportion = 0,
depth = 0.92,
width = 0.85,
},
bodyColors = {
leftArmColorId = 1030,
torsoColorId = 1001,
rightArmColorId = 1030,
headColorId = 1030,
leftLegColorId = 1001,
rightLegColorId = 1001,
},
assets = {
{
id = 1031492,
assetType = {
name = "Hat",
id = 8,
},
name = "Striped Hat",
},
{
id = 13062491,
assetType = {
name = "Face Accessory",
id = 42,
},
name = "Vision Française ",
},
{
id = 16598440,
assetType = {
name = "Neck Accessory",
id = 43,
},
name = "Red Bow Tie",
},
{
id = 28999228,
assetType = {
name = "Face",
id = 18,
},
name = "Joyous Surprise",
},
{
id = 86896488,
assetType = {
name = "Shirt",
id = 11,
},
name = "Expensive Red Tuxedo Jacket",
},
{
id = 86896502,
assetType = {
name = "Pants",
id = 12,
},
name = "Expensive Red Tuxedo Pants",
},
{
id = 376530220,
assetType = {
name = "Left Arm",
id = 29,
},
name = "ROBLOX Boy Left Arm",
},
{
id = 376531012,
assetType = {
name = "Right Arm",
id = 28,
},
name = "ROBLOX Boy Right Arm",
},
{
id = 376531300,
assetType = {
name = "Left Leg",
id = 30,
},
name = "ROBLOX Boy Left Leg",
},
{
id = 376531703,
assetType = {
name = "Right Leg",
id = 31,
},
name = "ROBLOX Boy Right Leg",
},
{
id = 376532000,
assetType = {
name = "Torso",
id = 27,
},
name = "ROBLOX Boy Torso",
},
},
}
print(result)

GetFriendsAsync

ผลตอบแทน

ฟังก์ชัน GetFriends Players กลับสิ่งที่เป็น FriendPages โอเอ็นที่มีข้อมูลสำหรับเพื่อนทั้งหมดของผู้ใช้ที่ให้ รายการภายใน FriendPages โอเอ็นมีฟิลด์ต่อไปนี้:


<tr>
<td>รหัส</td>
<td>int64</td>
<td>UserId ของเพื่อน</td>
</tr>
<tr>
<td>ชื่อผู้ใช้</td>
<td>สตริง</td>
<td>ชื่อผู้ใช้ของเพื่อน</td>
</tr>
<tr>
<td>แสดงชื่อ</td>
<td>สตริง</td>
<td>Class.Player.DisplayName|ชื่อแสดงผล ของเพื่อน</td>
</tr>
ชื่อชนิดคำอธิบาย

ดูตัวอย่างโค้ดสำหรับวิธีง่ายๆ ในการเรียกร้องผ่านเพื่อนของผู้เล่นทั้งหมด

พารามิเตอร์

userId: number

รหัสผู้ใช้ของผู้เล่นที่กำหนด


ส่งค่ากลับ

ตัวอย่างโค้ด

This code sample loads the Player.UserId of the player whose username is provided at the top of the script by using Players:GetUserIdFromNameAsync(). Then, it gets a FriendPages object by calling Players:GetFriendsAsync() and iterates over each entry using the iterPageItems function. The username of each friend is stored in a table, then printed at the end.

Print Roblox Friends

local Players = game:GetService("Players")
local USERNAME = "Cozecant"
local function iterPageItems(pages)
return coroutine.wrap(function()
local pagenum = 1
while true do
for _, item in ipairs(pages:GetCurrentPage()) do
coroutine.yield(item, pagenum)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
pagenum = pagenum + 1
end
end)
end
-- First, get the user ID of the player
local userId = Players:GetUserIdFromNameAsync(USERNAME)
-- Then, get a FriendPages object for their friends
local friendPages = Players:GetFriendsAsync(userId)
-- Iterate over the items in the pages. For FriendPages, these
-- are tables of information about the friend, including Username.
-- Collect each username in a table
local usernames = {}
for item, _pageNo in iterPageItems(friendPages) do
table.insert(usernames, item.Username)
end
print("Friends of " .. USERNAME .. ": " .. table.concat(usernames, ", "))

GetHumanoidDescriptionFromOutfitId

ผลตอบแทน

กลับค่า HumanoidDescription สำหรับชุดอันตรงสำหรับชุดอันตรงสำหรับชุด ซึ่งจะถูกกำหนดด้วยส่วน/สี/อนิเมชั่นต่างๆ ของชุด ชุดสามารถถูกสร้างโดยผู้ใช้หรือสามารถเป็นชุดสำหรับกลุ่มที่ถูกสร้างโดย Roblox

พารามิเตอร์

outfitId: number

รหัสของเครื่องแต่งกายที่มีคำอธิบายมนุษย์


ส่งค่ากลับ

HumanoidDescription ได้รับการระบุด้วยคุณลักษณะสำหรับชุดที่ผ่านใน outfitId

ตัวอย่างโค้ด

Shows how to get the HumanoidDescription for bundle 799 (Fishman).

Get HumanoidDescription From Outfit ID

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local function getOutfitId(bundleId)
if bundleId <= 0 then
return
end
local info = game.AssetService:GetBundleDetailsAsync(bundleId)
if not info then
return
end
for _, item in pairs(info.Items) do
if item.Type == "UserOutfit" then
return item.Id
end
end
return nil
end
local function getHumanoidDescriptionBundle(bundleId)
local itemId = getOutfitId(bundleId)
if itemId and itemId > 0 then
return Players:GetHumanoidDescriptionFromOutfitId(itemId)
end
return nil
end
local humanoidDescription = getHumanoidDescriptionBundle(799)
local humanoidModel = Players:CreateHumanoidModelFromDescription(humanoidDescription, Enum.HumanoidRigType.R15)
humanoidModel.Parent = Workspace

GetHumanoidDescriptionFromUserId

ผลตอบแทน

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

พารามิเตอร์

userId: number

รหัสผู้ใช้สำหรับผู้ใช้ Roblox (The UserId คือเลขที่อยู่ในโปรไฟล์ของผู้ใช้เช่น www.roblox.com/users/1/profile)


ส่งค่ากลับ

HumanoidDescription ได้รับการระบุด้วยค่าของ avatar ของผู้ใช้

ตัวอย่างโค้ด

This code sample shows how to use GetHumanoidDescriptionFromUserId() to create a Humanoid Model.

Get HumanoidDescription From User ID

game.Players:CreateHumanoidModelFromDescription(game.Players:GetHumanoidDescriptionFromUserId(1), Enum.HumanoidRigType.R15).Parent = game.Workspace

GetNameFromUserIdAsync

ผลตอบแทน

ฟังก์ชัน GetNameFromUserIdAsync Players จะส่งคำถามไปยังเว็บไซต์ Roblox โดยถามว่าชื่อผู้ใช้บัญชีนั้นมี UserId ที่ให้ไว้

วิธีนี้ผิดหากไม่มีบัญชีใด ๆ ที่มี UserId ที่ให้ หากคุณไม่แน่ใจว่าบัญชีดังกล่าวมีอยู่จริง คุณควรห่อเรียกให้กับฟังก์ชันนี้ด้วย pcall นอกจากนี้คุณยังสามารถเก็บ

พารามิเตอร์

userId: number

Class.Player.UserId ของผู้เล่นที่กำหนด


ส่งค่ากลับ

ชื่อผู้ใช้ที่มี Player.UserId ที่กำหนด

ตัวอย่างโค้ด

This code sample demonstrates using the Players:GetNameFromUserIdAsync() method to get a user's Player.Name from their Player.UserId.

Get Name from UserId

local Players = game:GetService("Players")
-- Example Data:
-- UserId: 118271 Name: "RobloxRulez"
-- UserId: 131963979 Name: "docsRule"
local nameOne = Players:GetNameFromUserIdAsync(118271)
local nameTwo = Players:GetNameFromUserIdAsync(131963979)
print(nameOne, nameTwo)
-- prints: "RobloxRulez docsRule"

This code sample demonstrates using the Players:GetNameFromUserIdAsync() method to get a user's Player.Name from their Player.UserId. Because GetNameFromUserIdAsync() yields, you can avoid calling it for the same Name using a table to store each UserId:Name pair found, called a cache. pcall() is used to catch the failure in case the Name doesn't exist.

Get Name from UserId using a cache

local Players = game:GetService("Players")
-- Create a table called 'cache' to store each 'Name' as they are found.
-- If we lookup a 'Name' using the same 'UserId', the 'Name' will come
-- from cache (fast) instead of GetNameFromUserIdAsync() (yields).
local cache = {}
function getNameFromUserId(userId)
-- First, check if the cache contains 'userId'
local nameFromCache = cache[userId]
if nameFromCache then
-- if a value was stored in the cache at key 'userId', then this 'nameFromCache'
-- is the correct Name and we can return it.
return nameFromCache
end
-- If here, 'userId' was not previously looked up and does not exist in the
-- cache. Now we need to use GetNameFromUserIdAsync() to look up the name
local name
local success, _ = pcall(function()
name = Players:GetNameFromUserIdAsync(userId)
end)
if success then
-- if 'success' is true, GetNameFromUserIdAsync() successfully found the
-- name. Store this name in the cache using 'userId' as the key so we
-- never have to look this name up in the future. Then return name.
cache[userId] = name
return name
end
-- If here, 'success' was false, meaning GetNameFromUserIdAsync()
-- was unable to find the 'name' for the 'userId' provided. Warn the user
-- this happened and then return nothing, or `nil`.
warn("Unable to find Name for UserId:", userId)
return nil
end
-- Example Data:
-- UserId: 118271 Name: "RobloxRulez"
-- UserId: 131963979 Name: "docsRule"
-- The first time a UserId is used, GetNameFromUserIdAsync() will be called
local nameOne = getNameFromUserId(118271)
local nameTwo = getNameFromUserId(131963979)
-- Because 118271 was previously used, get its Name from the cache
local nameOneQuick = getNameFromUserId(118271)
print(nameOne, nameTwo, nameOneQuick)
-- prints: "RobloxRulez docsRule RobloxRulez"

GetUserIdFromNameAsync

ผลตอบแทน

ฟังก์ชันนี้จะส่งคำถามไปยังเว็บไซต์ Roblox ถามว่า Player.UserId เป็นของบัญชีด้วยชื่อ Player ที่ให้

วิธีนี้ผิดหากไม่มีบัญชีใด ๆ ที่มีชื่อผู้ใช้ที่ให้ หากคุณไม่แน่ใจว่าบัญชีดังกล่าวมีอยู่จริงหรือไม่ จะแนะนำให้ห่อคำเรียกในหน้านี้ด้วย pcall นอกจากนี้คุณยังส

พารามิเตอร์

userName: string

ชื่อผู้ใช้ของผู้เล่นที่กำหนด


ส่งค่ากลับ

Class.Player.UserId ของผู้ใช้ที่มีชื่อระบุ

ตัวอย่างโค้ด

This code sample demonstrates using the Players:GetUserIdFromNameAsync() method to get a user's Player.UserId from their Player.Name.

Get UserId from Name

local Players = game:GetService("Players")
-- Example Data:
-- UserId: 118271 Name: "RobloxRulez"
-- UserId: 131963979 Name: "docsRule"
local userIdOne = Players:GetUserIdFromNameAsync("RobloxRulez")
local userIdTwo = Players:GetUserIdFromNameAsync("docsRule")
print(userIdOne, userIdTwo)
-- prints: "118271 131963979"

This code sample demonstrates using the Players:GetUserIdFromNameAsync() method to get a user's Player.UserId from their Player.Name. Because GetUserIdFromNameAsync() yields, you can avoid calling it for the same UserId using a table to store each Name:UserId pair found, called a cache. pcall() is used to catch the failure in case the UserId doesn't exist.

Get UserId from Name using a cache

local Players = game:GetService("Players")
-- Create a table called 'cache' to store each 'UserId' as they are found.
-- If we lookup a 'UserId' using the same 'Name', the 'UserId' will come
-- from cache (fast) instead of GetUserIdFromNameAsync() (yields).
local cache = {}
function getUserIdFromName(name)
-- First, check if the cache contains 'name'
local userIdFromCache = cache[name]
if userIdFromCache then
-- if a value was stored in the cache at key 'name', then this 'userIdFromCache'
-- is the correct UserId and we can return it.
return userIdFromCache
end
-- If here, 'name' was not previously looked up and does not exist in the
-- cache. Now we need to use GetUserIdFromNameAsync() to look up the userId
local userId
local success, _ = pcall(function()
userId = Players:GetUserIdFromNameAsync(name)
end)
if success then
-- if 'success' is true, GetUserIdFromNameAsync() successfully found the
-- userId. Store this userId in the cache using 'name' as the key so we
-- never have to look this userId up in the future. Then return userId.
cache[name] = userId
return userId
end
-- If here, 'success' was false, meaning GetUserIdFromNameAsync()
-- was unable to find the 'userId' for the 'name' provided. We can warn the
-- user this happened and then return nothing, or `nil`.
warn("Unable to find UserId for Name:", name)
return nil
end
-- Example Data:
-- UserId: 118271 Name: "RobloxRulez"
-- UserId: 131963979 Name: "docsRule"
-- The first time a Name is used, GetUserIdFromNameAsync() will be called
local userIdOne = getUserIdFromName("RobloxRulez")
local userIdTwo = getUserIdFromName("docsRule")
-- Because "RobloxRulez" was previously used, get its UserId from the cache
local userIdOneQuick = getUserIdFromName("RobloxRulez")
print(userIdOne, userIdTwo, userIdOneQuick)
-- prints: "118271 131963979 118271"

GetUserThumbnailAsync

ผลตอบแทน

ฟังก์ชันนี้กลับรายละเอียด URL ผู้เล่นโดยมีขนาดภาพที่ต้องการเป็น UserId ขนาดของภาพที่ต้องการเป็น Enum.ThumbnailSize ขนาดของภ

ในกรณีส่วนใหญ่, วิธีนี้ใช้กับ ImageLabel.Image หรือ Decal.Texture เพื่อแสดงภาพตัวละครของผู้ใช้ในประสบการณ์

พารามิเตอร์

userId: number

Class.Player.UserId ของผู้เล่นที่กำหนด

thumbnailType: Enum.ThumbnailType

A Enum.ThumbnailType อธิบายประเภทของไฟล์รูปภาพ

thumbnailSize: Enum.ThumbnailSize

A Enum.ThumbnailSize ภาพขนาดย่อ


ส่งค่ากลับ

ชุดที่ประกอบด้วย URL ของเนื้อหาสำหรับรูปประกอบผู้ใช้ตามค่าประกอบที่กำหนดไว้และบูลที่ระบุว่ารูปภาพพร้อมให้ใช้หรือไม่

ตัวอย่างโค้ด

This code sample displays the current player's thumbnail in a parent ImageLabel by using Players:GetUserThumbnailAsync() and setting the Image() property as well as its Size().

Display Player Thumbnail

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local PLACEHOLDER_IMAGE = "rbxassetid://0" -- replace with placeholder image
-- fetch the thumbnail
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
-- set the ImageLabel's content to the user thumbnail
local imageLabel = script.Parent
imageLabel.Image = (isReady and content) or PLACEHOLDER_IMAGE
imageLabel.Size = UDim2.new(0, 420, 0, 420)

UnbanAsync

()
ผลตอบแทน

ยกเลิกการแบนผู้เล่นที่ถูกแบนจาก Players:BanAsync() หรือ ใช้งานสินค้าอิเล็กทรอนิกส์ API ผู้ใช้จำกัด นี้ วิธีนี้เปิดใช้งานและปิดใช้งานโดย Players.BanningEnabled ระ

เช่น Players:BanAsync() วิธีนี้ใช้คําศัพท์ config ที่จะช่วยให้คุณจัดการผู้ใช้ที่ได้รับการยกเลิกแบนออก นี่จัดการผู้ใช้ที่ไม่ได้รับการยกเลิกและขอบเขตจาก

การยกเลิกการแบนจะมีผลเฉพาะกับการแบนที่มี ApplyToUniverse สเก็ตต์เดียวกัน ตัวอย่างเช่น, การยกเลิกการแบนที่มี

วิธีนี้เรียกใช้การโทรแบบ HTTP ไปยังบริการเบื้องหลัง ซึ่งจำกัดความและอาจล้มเห

เนื่องจากความเสี่ยงที่เกี่ยวข้องกับการแบนผู้ใช้ วิธีนี้อาจถูกเรียกในเซิร์ฟเวอร์เกมข้างหลังเท่านั้น การโทรจากด้านล่างของตัวแทนจะส่งผลในการเรียกใช้

API นี้ใช้ ระเบียบาดาลของผู้ใช้เปิด Cloud API คุณจะสามารถใช้ API เหล่านี้เพื่อจัดการการแบนในแอปพลิเคชันของบุคคลที่สาม

พารามิเตอร์

config: Dictionary

<tbody>
<tr>
<td><code>UserIds</code></td>
<td>รายการ</td>
<td>UserIDs ที่จะได้รับการอนุญาตให้เข้าสู่ประสบการณ์(s) ขนาดสูงสุดคือ <code>50</code></td>
</tr>
<tr>
<td><code>ใช้กับจักรวาล</code></td>
<td>บูลีน</td>
<td>แพร่กระจายการแบนทั้งหมดไปยังทุกสถานที่ในจักรวาลนี้</td>
</tr>
</tbody>
ชื่อชนิดคำอธิบาย

ส่งค่ากลับ

()

ตัวอย่างโค้ด

The following un-bans a user, as well as another unrelated account with UserId 789.

Unbanning Users

local Players = game:GetService("Players")
if shouldBeUnbanned(player) then
local config: UnbanConfigType = {
UserIds = {player.UserId, 789},
ApplyToUniverse = false
}
local success, err = pcall(function()
return Players:UnbanAsync(config)
end)
print(success, err)
end

อีเวนต์

PlayerAdded

เหตุการณ์ PlayerAdded เกิดขึ้นเมื่อผู้เล่นเข้าสู่เกม นี่ใช้เพื่อยิงเหตุการณ์เมื่อผู้เล่นเข้าร่วมเกม เช่น การโหลดข้อมูล GlobalDataStore ของผู้เล่น

นี้สามารถใช้ร่วมกับเหตุการณ์ Players.PlayerRemoving ซึ่งจะปล่อยให้เมื่อผู้เล่นกำลังจะออกจากเกม อินสแตนซ์


local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the game!")
end)
Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left the game!")
end)

หากคุณต้องการติดตามเมื่อตัวละครของผู้เล่นถูกเพิ่มหรือลบออกจากเกม เช่นเมื่อผู้เล่นเกิดใหม่หรือตาย คุณสามารถใช้คุณสมบัติ Player.CharacterAdded และ Player.CharacterRemoving ได้

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

พารามิเตอร์

player: Player

ตัวอย่างผู้เล่นที่เข้าร่วมเกม


ตัวอย่างโค้ด

This example will print "A player has entered: " followed by the name of the player that enters/joins a game every time a player joins.

Players.PlayerAdded

local Players = game:GetService("Players")
local function onPlayerAdded(player)
print("A player has entered: " .. player.Name)
end
Players.PlayerAdded:Connect(onPlayerAdded)

PlayerMembershipChanged

เหตุการณ์นี้จะเกิดขึ้นเมื่อเซิร์ฟเวอร์เกมรู้สึกว่าสมาชิกของผู้เล่นเปลี่ยนแปลงไปแล้ว หมายเหตุ อย่างไรก็ตาม เซิ

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

ดูเพิ่มเติม:

พารามิเตอร์

player: Player

ตัวอย่างโค้ด

The function in the code sample runs after the game server confirms a player's membership has changed. It demonstrates how you can grant players access to Premium benefits (or revoke them) when their membership status changes.

Handling Premium Membership Changes

local Players = game:GetService("Players")
local function grantPremiumBenefits(player)
-- Grant the player access to Premium-only areas, items, or anything you can imagine!
print("Giving", player, "premium benefits!")
end
local function playerAdded(player)
if player.MembershipType == Enum.MembershipType.Premium then
grantPremiumBenefits(player)
end
end
local function playerMembershipChanged(player)
print("Received event PlayerMembershipChanged. New membership = " .. tostring(player.MembershipType))
if player.MembershipType == Enum.MembershipType.Premium then
grantPremiumBenefits(player)
end
end
Players.PlayerAdded:Connect(playerAdded)
Players.PlayerMembershipChanged:Connect(playerMembershipChanged)

PlayerRemoving

กิจกรรม PlayerRemoving เกิดขึ้นทันทีก่อนที่ Player จะออกจากเกม กิจกรรมนี้เกิดขึ้นก่อนที่ Class.

นี้สามารถใช้ร่วมกับเหตุการณ์ Player.PlayerAdded ซึ่งจะเปิดใช้งานเมื่อผู้เล่นเข้าร่วมเกม อินสแตนซ์:


local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the game!")
end)
Players.PlayerRemoving:Connect(function(player)
print(player.Name .. " left the game!")
end)

หากคุณต้องการติดตามเมื่อตัวละครของผู้เล่นถูกเพิ่มหรือลบออกจากเกม เช่นเมื่อผู้เล่นเกิดใหม่หรือตาย คุณสามารถใช้คุณสมบัติ Player.CharacterAdded และ Player.CharacterRemoving ได้

พารามิเตอร์

player: Player

ตัวอย่างผู้เล่นที่กำลังออกจากเกม


ตัวอย่างโค้ด

This code will print "A player has left: ", followed by the player's name, every time a player leaves:

Players.PlayerRemoving

local Players = game:GetService("Players")
local function onPlayerRemoving(player)
print("A player has left: " .. player.Name)
end
Players.PlayerRemoving:Connect(onPlayerRemoving)

UserSubscriptionStatusChanged

เหตุการณ์นี้จะเกิดขึ้นเมื่อเซิร์ฟเวอร์เกมระзнаนี้ว่าผู้ใช้สถานะสำหรับการซื้อสมาชิกใหม่ในบางรายการได้เปลี่ยนแ

หมายเหตุว่าเฉพาะสคริปต์เซิร์ฟเวอร์เท่านั้นที่ได้รับเหตุการณ์นี้

พารามิเตอร์

user: Player

ผู้ใช้ที่สถานะสมัครใช้เปลี่ยนแปลง

subscriptionId: string

รหัสสมาชิกรับการเปลี่ยนแปลงสถานะ