Policy Info For Player

local PolicyService = game:GetService("PolicyService")
local player = game.Players.LocalPlayer
 
local result, policyInfo = pcall(function()
	return PolicyService:GetPolicyInfoForPlayerAsync(player)
end)
 
if not result then
	warn("PolicyService error: " .. policyInfo)
elseif policyInfo.ArePaidRandomItemsRestricted then
	warn("Player cannot interact with paid random item generators")
end

I added this code as LocalScript to StarterPlayerScript so that my experience conforms to the ArePaidRandomItemsRestricted policy API

Is there anything else I need to do to comply with this policy? So my game has Paid Random Items policy like Boombox and do I need to do anything to Boombox codes or something else or is it enough to just have this code in my game to comply this policy?

In short
With this code we only get Policy Information for a Player, so what else do I need to do?

1 Like

You need to disable the Paid randomizer you have (for the player), if PolicyService says they aren’t allowed to interact with it. The code by itself doesn’t comply because it doesn’t do anything

Is there an example of this? So I already guessed something like this but I don’t know exactly how to do it

For example, if you have a button that would bring up a paid randomized spinner, when the player clicks on the button, make sure that they interact with it before allowing it to be shown on their screen:

-- Example
GuiButton.MouseButton1Click:Connect(function()
   local policy = PolicyService:GetPolicyInfoForPlayerAsync(LocalPlayer)
   
   if policy.ArePaidRandomItemsRestricted then
       -- Player cannot interact with the spinner, so don't show it
       print("User cannot see spinner")
   else
       -- Player can interact with the spinner, so you can show it
       Spinner.Visible = true
   end
end)

If you don’t want to call the GetPolicyInfoForPlayerAsync method everytime, you can cache the result of it when they initially join the game and read from the cache whenever you need to

I know I’m going to look uninformed by asking this, but I really have little knowledge of coding so I’m asking, is there an example of this too, one I can look at there?

-- Example (on the server)
local cache = {}

local function SaveCache(player: Player)
   -- Save the player's temporary data to a table (using their UserId as the key)
   cache[player.UserId] = PolicyService:GetPolicyInfoForPlayerAsync(player)
end

local function GetCache(player: Player)
   -- Returns the policy info data associated with the player
   return cache[player.UserId]
end

Players.PlayerAdded:Connect(SaveCache) -- Connect the SaveCache function to each time a player joins
RemoteFunction.OnServerInvoke = GetCache -- Return the cache result when the client request's it
-- Example (Client)
-- Using the button example from earlier
GuiButton.MouseButton1Click:Connect(function()
   local policy = RemoteFunction:InvokeServer() -- Get the user's PolicyInfo cache
   
   if policy.ArePaidRandomItemsRestricted then
       -- Player cannot interact with the spinner, so don't show it
       print("User cannot see spinner")
   else
       -- Player can interact with the spinner, so you can show it
       Spinner.Visible = true
   end
end)

Make sure you erase the table entry once they leave