Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to get account age from UserID?

Asked by
NordicM 77
4 years ago

I want to be able to find players account age without them being in the game. It's easy to find players account age when they are in the game...

local player = game.Players.NordicM --Using my IGN for this example
print(tostring(player.AccountAge))

Is there any possible way to get a players account age from a UserID?

I've seen people getting a players account age from an api. If you can't get a players account age from a UserID, how do you do get information from an api

1 answer

Log in to vote
-1
Answered by 4 years ago

The AccountAge is a Player property that describes how long ago a player’s account was registered in days. It is set using the Player:SetAccountAge function, which cannot be accessed by scripts.

This property is useful for conditionally showing new Roblox players content such as tutorials.

for example:

local Players = game:GetService("Players")

local MAX_AGE_NEW_PLAYER = 7 -- a week
local MIN_AGE_VETERAN = 365 -- one year

-- This function marks a part with text using a BillboardGui
local function mark(part, text)
    local bbgui = Instance.new("BillboardGui")
    bbgui.AlwaysOnTop = true
    bbgui.StudsOffsetWorldSpace = Vector3.new(0, 2, 0)
    bbgui.Size = UDim2.new(0, 200, 0, 50)
    local textLabel = Instance.new("TextLabel")
    textLabel.Size = UDim2.new(1, 0, 1, 0) -- Fill parent
    textLabel.Text = text
    textLabel.TextColor3 = Color3.new(1, 1, 1)
    textLabel.TextStrokeTransparency = 0
    textLabel.BackgroundTransparency = 1
    textLabel.Parent = bbgui
    -- Add to part
    bbgui.Parent = part
    bbgui.Adornee = part
end

local function onPlayerSpawned(player, character)
    local head = character:WaitForChild("Head")
    if player.AccountAge >= MIN_AGE_VETERAN then
        mark(head, "Veteran Player")
    elseif player.AccountAge <= MAX_AGE_NEW_PLAYER then
        mark(head, "New Player")
    else
        mark(head, "Regular Player")
    end
end

local function onPlayerAdded(player)
    -- Listen for this player spawning
    if player.Character then
        onPlayerSpawned(player, player.Character)
    end
    player.CharacterAdded:Connect(function ()
        onPlayerSpawned(player, player.Character)
    end)
end

-- Listen for players being added
for _, player in pairs(Players:GetPlayers()) do
    onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
0
This is not what I was after... Did you read my description? This only works if they join the game... I want it to work like how you can get an avatar thumbnail from a UserID NordicM 77 — 4y
Ad

Answer this question