PolicyService

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
服务
未复制

PolicyService 帮助您根据年龄范围、位置和平台输入查询全球玩家的政策遵守情况。

概要

方法

属性

方法

CanViewBrandProjectAsync

暂停

决定用户是否可以在体验中查看品牌项目资产。这种方法可以让你与品牌合作,仅向品牌兼容的受众显示商业资产。

要使用 CanViewBrandProjectAsync,您必须使用 Roblox 提供的品牌项目 ID。要请求品牌项目 ID,请 联系我们

您必须在服务器端的脚本上调用此方法并将其包装在 pcall() 中。

参数

player: Player

你正在尝试向品牌项目展示的 Player 对象。

默认值:""
brandProjectId: string

Roblox 提供的品牌项目 ID 代表与品牌项目相关的所有资产。

默认值:""

返回

品牌项目是否可以向特定用户显示。

代码示例

You must call CanViewBrandProjectAsync from the server-side and then fire an event on the client. Calling this method from the client-side returns an error.

Server-side code sample

-- In ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PolicyService = game:GetService("PolicyService")
-- Pre-created RemoteEvent in ReplicatedStorage
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local brandedAsset = ReplicatedStorage:WaitForChild("BrandedAsset")
local defaultAsset = Instance.new("Part")
Players.PlayerAdded:Connect(function(player)
-- PolicyService:CanViewBrandProjectAsync can only be called from the Server
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)
Client-side code sample

-- In StarterPlayerScripts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Pre-created RemoteEvent in ReplicatedStorage
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
RemoteEvent.OnClientEvent:Connect(function(partToLoad)
local clonedPart = partToLoad:Clone()
clonedPart.Parent = workspace
end)

GetPolicyInfoForPlayerAsync

暂停

根据地理定位、年龄群组和平台返回关于玩家的政策信息。返回词典的结构如下:


<th>类型</th>
<th>需要为</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>允许广告吗</code></td>
<td>Boolean 值</td>
<td>包含 <a href="/production/monetization/immersive-ads">沉浸广告</a> 的任何体验。</td>
<td>当 <code>true</code> 时,玩家可能会在体验中看到沉浸式广告。</td>
</tr>
<tr>
<td><code>是否付费随机项目受限</code></td>
<td>Boolean 值</td>
<td>任何拥有付费随机物品的体验。</td>
<td>当 true 时,玩家无法与付费随机物品生成器进行互动,也不能通过 Robux 或 Robux 直接购买体验货币。</td>
</tr>
<tr>
<td><code>允许外部链接引用</code></td>
<td>阵列</td>
<td>任何引用外部链接的经验。</td>
<td>一列外部链接参考,例如社交媒体链接、手柄或图标,玩家可以查看。可能的值包括 <code>"Discord"</code> , <code>"Facebook"</code> , <code>"Twitch"</code> , <code>"YouTube"</code> , <code>"X"</code> , <code>"GitHub"</code> , 和 <code>"Guilded"</code> .</td>
</tr>
<tr>
<td><code>是否允许共享内容</code></td>
<td>Boolean 值</td>
<td>任何允许用户在平台之外分享内容的体验。</td>
<td>当 <code>true</code> 时,玩家可以使用打开外部共享流程的 API 分享内容,例如 <code>Class.CaptureService:PromptShareCapture()|PromptShareCapture()</code> 。</td>
</tr>
<tr>
<td><code>是否有资格购买订阅</code></td>
<td>Boolean 值</td>
<td>任何想要出售订阅的经验。</td>
<td>当 <code>true</code> 时,玩家有资格在体验中购买订阅。</td>
</tr>
<tr>
<td><code>是否允许交易付费物品</code></td>
<td>Boolean 值</td>
<td>任何允许用户购买虚拟物品来与其他玩家交易的体验。</td>
<td>当 <code>true</code> 时,玩家可以用经验货币或 Robux 购买的虚拟物品进行交易。</td>
</tr>
<tr>
<td><code>是否受中国政策影响</code></td>
<td>Boolean 值</td>
<td>在中国可用的任何体验。</td>
<td>当 <code>true</code> 时,体验应强制执行更改。请参阅 <a href="https://devforum.roblox.com/t/new-programs-available-roblox-china-licensed-to-operate/1023361">此论坛帖子</a> 获取更多信息。</td>
</tr>
</tbody>
名称
例外

与任何异步调用一样,此方法需要被包装在 pcall() 中,并且错误处理得当。完整列出可能的错误消息和其原因是:


<th>原因</th>
</tr>
</thead>
<tbody>
<tr>
<td>实例不是玩家</td>
<td>玩家 <code>参数</code> 不是 <code>Class.Player</code> 实例。</td>
</tr>
<tr>
<td>未找到玩家</td>
<td>内部错误,该 <code>Class.Players</code> 对象缺少。</td>
</tr>
<tr>
<td>无法在客户端调用非本地玩家的此方法</td>
<td>无法在客户端调用非本地 <code>Class.Player</code> 。</td>
</tr>
<tr>
<td>GetPolicyInfoForPlayerAsync 被调用了太多次</td>
<td>内部错误,该 <code>GetPolicyInfoForPlayerAsync()</code> 被调用超过 100 次(当前设置),直到 HTTP 响应返回。</td>
</tr>
</tbody>
消息

还请参阅LocalizationService:GetCountryRegionForPlayerAsync(),该方法返回按照玩家客户端 IP 地理定位的国家/地区代码字符串。

参数

player: Instance

获取政策信息的 Player

默认值:""

返回

包含请求玩家政策信息的词典;请参阅上面的词典结构。

代码示例

This code sample gets policy information for the local player and warns if they cannot interact with paid random item generators.

Getting Policy Information for a Player

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 error: " .. result)
elseif result.ArePaidRandomItemsRestricted then
warn("Player cannot interact with paid random item generators")
end

活动