Argument 1 is missing or nil, trying to get 13+ status

Error:
image
Code:

warn("Checking <13 or 13+ status..")
wait()
local id = math.random(9999,999999)	
warn("Ticket id:"..id)
if game:GetService("PolicyService"):GetPolicyInfoForPlayerAsync().AllowedExternalLinkReferences == true then
	print("User is 13+. Content unrestricted.")
else
	print ("User is <13. Some content may be restricted.")
	warn("This may be an error. If this is incorrect, HttpService is down. Contact us.")

end

Hi!
The error is as the title says.
What’s wrong?
Thanks!

GetPolicyInfoForPlayerAsync expects a player instance to get policy info for, you gave the function nothing

So is there a way I can get the 13+ data without that?

Well judging by the fact that this is in PlayerGui, I assume it’s a localscript, just use the Localplayer as the player instance

1 Like

image

GetPolicyInfoForPlayerAsync(game.Players.LocalPlayer) this works maybe

here

warn("Checking <13 or 13+ status..")
wait()
local id = math.random(9999,999999)	
warn("Ticket id:"..id)
if game:GetService("PolicyService"):GetPolicyInfoForPlayerAsync(game.Players.LocalPlayer).AllowedExternalLinkReferences == true then
	print("User is 13+. Content unrestricted.")
else
	print ("User is <13. Some content may be restricted.")
	warn("This may be an error. If this is incorrect, HttpService is down. Contact us.")

end

I think its GetPolicyInfoForPlayerAsync(game.Players.LocalPlayer.UserId) isnt it ? Correct me if wrong.

Did you pass in the argument incorrectly? You’re supposed to reference the localplayer in the brackets of GetPolicyInfoForPlayerAsync

@XRHTech No, the function expects a player instance

@Creeperman16487 game:GetService("Players").LocalPlayer would be a bit more recommended as it’s the safer method

1 Like

well i just looked up and its not userid it needs the player instance

is using a pcall needed here? just asking cuz it said in devhub it needs error handling or something

That would be the most recommended approach to ensure everything goes smoothly, think this would be the best approach

local PolicyService = game:GetService("PolicyService")

warn("Checking <13 or 13+ status..")
local id = math.random(9999,999999)	
warn("Ticket id:"..id)

local success, info = pcall(PolicyService.GetPolicyInfoForPlayerAsync, PolicyService, game:GetService("Players").LocalPlayer)

if success then
	if info.AllowedExternalLinkReferences then
		print("User is 13+. Content unrestricted.")
	else
		print("User is <13. Some content may be restricted.")
	end
else
	warn(info)
end
1 Like

If it says it should have error handling then give it error handling. It is making a web call which could fail for various reasons–the dev hub also explains why.

local PolicyService = game:GetService("PolicyService")
local Players = game:GetService("Players")

local Client = Players.LocalPlayer
local PolicySuccess, PolicyResponse = pcall(PolicyService.GetPolicyInfoForPlayerAsync, PolicyService, Client)

if PolicySuccess and PolicyResponse.AllowedExternalLinkReferences then
    -- 13+
else
    -- I would assume they are < 13 if the web call fails or if they're not allowed to see external.
    -- or you could implement a system to retry the call. 
end

I like that, is there a way to add that to your code?

If I had to assume, probably having a repeat until loop go on until the first return is true or the amount of retries have been exceeded, something like this

local PolicyService = game:GetService("PolicyService")

warn("Checking <13 or 13+ status..")
wait()
local id = math.random(9999,999999)	
warn("Ticket id:"..id)

local success, info

local limit = 0

repeat
	limit += 1
	success, info = pcall(PolicyService.GetPolicyInfoForPlayerAsync, PolicyService, game:GetService("Players").LocalPlayer
until success or limit >= 3

if success then
	if info.AllowedExternalLinkReferences then
		print("User is 13+. Content unrestricted.")
	else
		print("User is <13. Some content may be restricted.")
	end
else
	warn(info)
end

Would repeat until it was successful or it has retried 3 times

1 Like