Engine Class
PolicyService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
วิธีการ
CanViewBrandProjectAsync(player: Player,brandProjectId: string):boolean |
เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
CanViewBrandProjectAsync
ส่งค่ากลับ
ตัวอย่างโค้ด
ตัวอย่างโค้ดฝั่งเซิร์ฟเวอร์
-- ใน ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PolicyService = game:GetService("PolicyService")
-- RemoteEvent ที่สร้างไว้ล่วงหน้าใน ReplicatedStorage
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local brandedAsset = ReplicatedStorage:WaitForChild("BrandedAsset")
local defaultAsset = Instance.new("Part")
Players.PlayerAdded:Connect(function(player)
-- PolicyService:CanViewBrandProjectAsync สามารถเรียกใช้ได้จากเซิร์ฟเวอร์เท่านั้น
local success, canView = pcall(function()
return PolicyService:CanViewBrandProjectAsync(player, "BRP-0123456789")
end)
if success and canView then
RemoteEvent:FireClient(player, brandedAsset)
else
RemoteEvent:FireClient(player, defaultAsset)
end
end)ตัวอย่างโค้ดฝั่งไคลเอนต์
-- ใน StarterPlayerScripts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- RemoteEvent ที่สร้างไว้ล่วงหน้าใน ReplicatedStorage
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
RemoteEvent.OnClientEvent:Connect(function(partToLoad)
local clonedPart = partToLoad:Clone()
clonedPart.Parent = workspace
end)GetPolicyInfoForPlayerAsync
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การดึงข้อมูลนโยบายสำหรับผู้เล่น
local PolicyService = game:GetService("PolicyService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local success, result = pcall(function()
return PolicyService:GetPolicyInfoForPlayerAsync(player)
end)
if not success then
warn("ข้อผิดพลาดของ PolicyService: " .. result)
elseif result.ArePaidRandomItemsRestricted then
warn("ผู้เล่นไม่สามารถโต้ตอบกับเครื่องมือสุ่มแบบเสียเงินได้")
endการรับข้อมูลนโยบายสำหรับผู้เล่น
local PolicyService = game:GetService("PolicyService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local success, result = pcall(function()
return PolicyService:GetPolicyInfoForPlayerAsync(player)
end)
if not success then
warn("เกิดข้อผิดพลาดใน PolicyService: " .. result)
elseif not result.IsEligibleToPurchaseCommerceProduct then
warn("ผู้เล่นไม่สามารถซื้อผลิตภัณฑ์จากการค้าได้")
end